[英]mysql_num_rows equivalent in aura sql
Hi am using Aura sql
to perform querying. 嗨,我正在使用Aura sql
执行查询。 What is the equivalent function for mysql_num_rows
in aura sql
. aura sql
mysql_num_rows
的等效功能是什么mysql_num_rows
I have to check: 我必须检查:
if(mysql_num_rows($query)==1)
// do something
else
// do something
For this i need the equivalent function in Aura.Sql
. 为此,我需要Aura.Sql
的等效功能。
Aura.Sql uses PDO internally. Aura.Sql在内部使用PDO。 The equivalent to mysql_num_rows http://www.php.net/manual/en/function.mysql-num-rows.php points to http://www.php.net/manual/en/pdostatement.rowcount.php . 相当于mysql_num_rows http://www.php.net/manual/zh/function.mysql-num-rows.php指向http://www.php.net/manual/en/pdostatement.rowcount.php 。
If you are using v1 of aura insert, update, delete etc always returns the number of affected rows. 如果您正在使用光环的v1插入,更新,删除等操作,则始终返回受影响的行数。 See https://github.com/auraphp/Aura.Sql/blob/develop/src/Aura/Sql/Connection/AbstractConnection.php#L953 . 参见https://github.com/auraphp/Aura.Sql/blob/develop/src/Aura/Sql/Connection/AbstractConnection.php#L953 。
If you are using a select statement you could make use of the count() or you can use fetchOne https://github.com/auraphp/Aura.Sql/tree/develop#fetching-results . 如果您使用的是select语句,则可以使用count(),也可以使用fetchOne https://github.com/auraphp/Aura.Sql/tree/develop#fetching-results 。
So in this case I will say 所以在这种情况下,我会说
// 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)) {
}
Let me know if that helps! 让我知道是否有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.