2009-10-20 113 views
3

我期待計數由下面使用的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 id,vcref,jobtitle,jobtype,jobintro,closingdate FROM jobs WHERE active = 1'); 
$stmt->execute(); 
$stmt->store_result; 
$stmt->bind_result($id,$vcref,$jobtitle,$jobtype,$jobintro,$closingdate); 
$stmt->fetch(); 
$totalLiveJobs = $stmt->num_rows(); 

輸出是consistantly 0

+2

多少,如果你直接在數據庫執行它應該返回? – Ismael 2009-10-20 14:00:10

+0

我知道有2行相匹配的查詢條件 - 這是一個思想家 – 2009-10-20 14:14:04

回答

8

你」在OOP風格中重新使用mysql_stmt_num_rows,因此將其作爲函數調用是不正確的。嘗試:

$stmt->num_rows; 

代替:

$stmt->num_rows(); 

基本上,你正在試圖獲得該值:

class mysqli_stmt { 

    int num_rows 

} 

此外,

$stmt->store_result; 

應該是:

$stmt->store_result(); 
+0

THX輸入M8 - 我仍然得到使用OOP風格, 我想我做對了嗎?在最後一行代碼中?試圖將值分配給一個變量? – 2009-10-20 14:16:01

+0

沒有,$ stmt-> NUM_ROWS()是調用$語句中不存在的方法,而$ stmt-> NUM_ROWS引用(這確實有一個值)的屬性。見http://phpbuilder.com/manual/en/function.mysqli-stmt-num-rows.php – karim79 2009-10-20 14:21:57

+0

THX卡里姆 - 現在我明白了,(用於連接額外的榮譽太)。 它現在工作得很好 - THX再次交配:) – 2009-10-20 14:27:29