2013-08-31 108 views
-2

我需要得到的结果行数PHP mysqli的语句数NUM_ROWS

$this-> db = new mysqli("localhost", "***", "***", "***") or die("Error ".mysqli_error($link)); 
$this-> db -> set_charset("utf8"); 

$query = "SELECT steps.id, steps.description, steps.sort, services.`name` AS service_name, services.short_name AS service_short_name, terminals.`name` AS terminal_name, terminals.short_name AS terminal_short_name FROM steps INNER JOIN instructions ON steps.page_id = instructions.id INNER JOIN services ON instructions.service_id = services.id INNER JOIN terminals ON instructions.terminal_id = terminals.id WHERE services.short_name = '{$service}' AND terminals.`name` = '{$terminal}' ORDER BY steps.sort"; 

if ($stmt = $this->db-> prepare($query)) { 
    $stmt -> execute(); 
    $stmt -> store_result(); 
    printf("row count: %d.\n", $stmt -> num_rows); 
    $stmt -> close(); 
} 

它返回零 - 但也有一些像10-15行

+0

你在你的数据库中至少有一行/ –

+0

@DarylGill我有一些像10-15行 – user2368299

+1

你测试了你的查询在phpmyadmin? – Mihai

回答

1

虽然“我做的不正确”是一个这个网站的外观问题,答案是:

说到获取行数,你做的一切都是正确的。
你的麻烦的唯一原因是你必须解决自己的一些数据/代码不一致。

说到使用准备好的语句,您正在使用它们是错误的,将变量直接添加到查询中,而您应该用占位符表示它们并稍后进行绑定。