1

Hi am using Aura sql to perform querying. What is the equivalent function for mysql_num_rows in aura sql.

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.

Hari K T
  • 4,174
  • 3
  • 32
  • 51
Deepu Sasidharan
  • 5,193
  • 10
  • 40
  • 97
  • http://auraphp.com/manuals/ – Sverri M. Olsen May 30 '14 at 06:41
  • @SverriM.Olsen manual is pointing to framework. It should be pointed to packages. http://auraphp.com/packages/Aura.Sql/ . next2u which version of Aura.Sql are you using? v1 or v2 ? – Hari K T Jun 02 '14 at 11:52
  • @HariKT, i download aura from here https://github.com/auraphp/Aura.Sql. i can't find the version from here. – Deepu Sasidharan Jun 02 '14 at 12:10
  • Does your composer.json look like https://github.com/auraphp/Aura.Sql/blob/develop/composer.json#L14-L17 . Especially having installer-default , php 5.4 ? – Hari K T Jun 02 '14 at 12:30

1 Answers1

1

Aura.Sql uses PDO internally. 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 .

If you are using v1 of aura insert, update, delete etc always returns the number of affected rows. See 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 .

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!

Hari K T
  • 4,174
  • 3
  • 32
  • 51