-2

我需要获取结果行数

$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();
}

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

4

1 回答 1

1

尽管“我做错了什么”是本网站的题外话,但答案是:

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

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

于 2013-08-31T09:45:42.197 回答