【问题标题】:mysql_num_rows equivalent in aura sqlmysql_num_rows 等效于 aura sql
【发布时间】:2014-05-30 06:40:09
【问题描述】:

您好,我正在使用Aura sql 执行查询。 aura sql中的mysql_num_rows的等效函数是什么。

我必须检查:

if(mysql_num_rows($query)==1)
 // do something
else
 // do something

为此,我需要Aura.Sql 中的等效函数。

【问题讨论】:

标签: php auraphp


【解决方案1】:

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

如果您使用 v1 的 aura 插入、更新、删除等始终返回受影响的行数。见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)) {
}

如果有帮助,请告诉我!

【讨论】:

  • 我目前正在为此使用结果计数..(您也规定了它),无论如何感谢您的宝贵回答,这将有助于我进一步的工作..
  • 很高兴听到:)。感谢您使用 Aura。
猜你喜欢
  • 2014-01-20
  • 2015-10-12
  • 1970-01-01
  • 1970-01-01
  • 2011-03-03
  • 1970-01-01
  • 1970-01-01
  • 2011-05-01
相关资源
最近更新 更多