您好,我正在使用Aura sql执行查询。在aura sql中,mysql_num_rows的等效功能是什么?
我得检查一下:
if(mysql_num_rows($query)==1)
// do something
else
// do something为此,我需要Aura.Sql中的等效函数。
发布于 2014-06-02 20:39:08
Aura.Sql在内部使用PDO。mysql_num_rows http://www.php.net/manual/en/function.mysql-num-rows.php的等价物指向http://www.php.net/manual/en/pdostatement.rowcount.php。
如果您正在使用aura insert、update、delete等的v1,则始终返回受影响的行数。参见https://github.com/auraphp/Aura.Sql/blob/develop/src/Aura/Sql/Connection/AbstractConnection.php#L953。
如果使用select语句,则可以使用count(),也可以使用fetchOne https://github.com/auraphp/Aura.Sql/tree/develop#fetching-results。
所以在这种情况下我会说
// the text of the query
$text = 'SELECT * FROM foo WHERE id = :id AND bar IN(:bar_list)';
// values to bind to query placeholders
$bind = [
'id' => 1,
'bar_list' => ['a', 'b', 'c'],
];
// returns all rows; the query ends up being
// "SELECT * FROM foo WHERE id = 1 AND bar IN('a', 'b', 'c')"
$result = $connection->fetchOne($text, $bind);
if (! empty($result)) {
}如果有帮助,请让我知道!
https://stackoverflow.com/questions/23948569
复制相似问题