Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php mysqli stmt count num_行_Php_Mysql_Mysqli - Fatal编程技术网

php mysqli stmt count num_行

php mysqli stmt count num_行,php,mysql,mysqli,Php,Mysql,Mysqli,我需要得到结果行计数 $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, service

我需要得到结果行计数

$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-0,但也有10-15行

虽然“我做的不正确”是本网站的一个离题问题,但答案是:

说到获得行数,您所做的一切都是正确的。
造成问题的唯一原因是数据/代码不一致,您必须自己解决


说到使用事先准备好的陈述,你用错了,将变量直接添加到查询中,而您应该使用占位符表示它们并稍后绑定。

您是否在phpmyadmin中测试了您的查询?尝试在mysql workbench或其他编辑器中测试您的查询,看看您的查询是否正确。您的变量设置是否正确?您是否尝试使用在这些行中找到的实际数据运行查询,以检查这是SQL还是PHP错误?@user2368299错误是什么?不要引用/反勾选您的表和列名。它们只会增加视觉上的混乱,只是你犯语法错误的又一种方式。您需要它们的唯一原因是如果您有一个保留字的列名,而使用保留字的列名是一个糟糕的主意,因此这是两个可以同时避免的坏习惯。