$ query-> result()返回null,但$ query-> num_rows()> 0

时间:2016-05-24 08:43:06

标签: php codeigniter sqlsrv

我在CI模型中有一个返回查询结果的函数。

function ambilDescription($productID)
    {
        $arrayHasil=$this->db->query("select * from tblMstProduct");
        var_dump($arrayHasil);
        if ($arrayHasil->num_rows() > 0) {
            foreach ($arrayHasil->result() as $data) {
                $hasil[] = $data;
            }
            return $hasil;
        }
    }

当我回复$arrayHasil->num_rows()

  

获得1行

但是当我print_r($arrayHasil->result())时,

  

数组()

这是var_dump($arrayHasil)

的结果
object(CI_DB_sqlsrv_result)#24 (8) { ["conn_id"]=> resource(34) of type (SQL Server Connection) ["result_id"]=> resource(47) of type (SQL Server Statement) ["result_array"]=> array(0) { } ["result_object"]=> array(0) { } ["custom_result_object"]=> array(0) { } ["current_row"]=> int(0) ["num_rows"]=> int(1347) ["row_data"]=> NULL }

如果我在SQL Server中运行那个查询,我会得到1行。

2 个答案:

答案 0 :(得分:2)

更改:

if ($arrayHasil->num_rows() > 0) {

if ($arrayHasil->num_rows > 0) {

答案 1 :(得分:0)

正确的语法是

if __name__ == "__main__":
app = Toplevel()
app.title("Extreme Points in Motion Segmentation of BVHs")
app.geometry('450x300+200+200')
btnSelectF = Button(text='Open BVH File',width='20', command=callback)
btnSelectF.pack()
label = Label(app,text="no File selected",height=4)
label.pack()
photo = PhotoImage(file="D:/AE theoretische Neuropsychologie/PythonReps/vCGPDM/Segmentation/image.gif")
w = Label(app, image=photo)
w.photo = photo
w.pack()
btnCompute = Button(text='Compute Segmentation',width='20', command=computeSegmentation)
btnCompute.pack()
btnCompute.config(state="disabled")
app.mainloop()

您也可以使用此方法(不推荐)

$arrayHasil->num_rows