0

我现在正在努力解决一个应该相当简单的事情。我想从我的 mysqli 数据库中获取行,当我从 phpmyadmin 运行查询时,我得到了预期的结果,但是当我with bind_param从我的 php 代码运行它()时,我得到 0 个结果:

$sql = $connection->prepare('SELECT (UNIX_TIMESTAMP(start_time)) 
                             FROM table1 
                             WHERE UNIX_TIMESTAMP(start_time) >= ? 
                               AND (UNIX_TIMESTAMP(start_time)) <= ? 
                               AND column3 = ?') 
                            or trigger_error($connection->error, E_USER_ERROR);
$sql->bind_param('sss', $value1, $value2, $value3);
$sql->execute() or trigger_error($sql->error, E_USER_ERROR);

if ($sql->num_rows == 0){
    echo "yay";
}
4

1 回答 1

1

您需要为 MySQLi 准备好的语句存储结果集。调整您的代码如下:

// Execute query
$sql->execute();

// Store result
$sql->store_result();

echo $sql->num_rows;

PHP 文档: http: //php.net/manual/en/mysqli-stmt.store-result.php http://php.net/manual/en/mysqli-stmt.num-rows.php

于 2015-11-12T17:44:17.250 回答