2013-05-20 33 views
0

我試圖讓下面的代碼工作,但它不工作,並給了我下面的錯誤mysqli的編制報表fetch_array

Fatal error: Call to a member function bind_param() on a non-object in 

有什麼辦法來獲取與預處理語句的數組?

if (move_uploaded_file($_FILES['file_to_upload']['tmp_name'], $final_uploads_location)) 
      { 
        $stmt = $mysqli->prepare("select * from test where `username` = ? and `age` = ? "); 
        $stmt->bind_param('ss', $username, $age); 
        $stmt->store_result(); 
        $stmt->execute(); 

        if($stmt->num_rows < 1) 
       { 
        $insert = $mysqli->prepare("insert into `test`(`username`, `age`,) values(?,?)"); 
        $insert->bind_param('ss', $username, $age); 
        $insert->execute(); 

       } 
       else 
       { 
        $check = mysqli_fetch_array($stmt); 
        global $identity; 
        } 
      } 

回答

0

準備好後查詢返回false(mysqli::prepare)。這意味着你的查詢有錯誤:未定義的字段,未知的表或其他東西。

+0

不錯,但即使我得到那個工作的mysqli_fetch_array將是一個麻煩的樣子。如何使用預處理語句獲取數組? –

+0

@MarkLubo,在查詢後探索[mysqli :: $ error](http://www.php.net/manual/en/mysqli.error.php) – sectus

0

嘗試在您的數據庫上執行確切的查詢。 我認爲它給你一個數據庫錯誤。

也許你的$ mysqli-> prepare返回一個「False」值。 通過這個你試圖調用一個不存在的布爾數據類型的「bind_param」函數。

0

$ stmt-> bind_param(「s」,$ username);

一次只能嘗試一個...您將每個聲明一個接一個地綁定。 然後你執行查詢。

這裏HERE