2009-10-28 13 views
0

我有PHP代碼從MySQL數據庫中選擇用戶詳細信息服務器上的錯誤!需要另一雙眼睛在簡單的php的mysqli

$mysql = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('There was a problem connecting to the database'); 
$stmt = $mysql->prepare('SELECT personalinfo.userid, personalinfo.firstname, personalinfo.lastname FROM personalinfo INNER JOIN applications ON personalinfo.userid = applications.userid WHERE applications.jobref = ?'); 
$stmt->bind_param('i',$jr); 
$stmt->execute(); 
$stmt->store_result(); 
$stmt->bind_result($userID,$firstName,$lastName); 
$count = $stmt->num_rows(); 

我已經localy測試此代碼在它的工作原理以下罰款,但是當我試圖測試上直播服務器,我不斷收到以下錯誤 「致命錯誤:調用一個成員函數bind_param()一個非對象在C:\路徑\爲\目錄下的」提前偷看

THX,

Aaron

任何

+0

我不能我愛我的眼睛 – Xinus 2009-10-28 18:46:36

回答

3

那麼,根據對mysqli::prepare()的文件,它將返回FALSE如果有一個錯誤,這是試圖調用$stmt->bind_param()因爲$stmt不是時候爲什麼你得到一個「無對象」錯誤這是一個對象。

因此,無論是爲了您目前的錯誤還是將來的任何錯誤,請務必在創建語句時檢查錯誤並採取相應措施。

$mysql = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('There was a problem connecting to the database'); 
$stmt = $mysql->prepare('SELECT personalinfo.userid, personalinfo.firstname, personalinfo.lastname FROM personalinfo INNER JOIN applications ON personalinfo.userid = applications.userid WHERE applications.jobref = ?'); 

if ($stmt) 
{ 
    $stmt->bind_param('i',$jr); 
    $stmt->execute(); 
    $stmt->store_result(); 
    $stmt->bind_result($userID,$firstName,$lastName); 
    $count = $stmt->num_rows(); 
} else { 
    // something went wrong 
    // perhaps display the error? 
    echo $mysql->error; 
} 
+0

THX彼得,我的幾個表已鎖定:S現在一切都很好,我會用這個結構來幫助捕捉錯誤更好的/在今後更快,謝謝muchos :) 亞倫 – 2009-10-28 18:57:53

相關問題