Jump to content

PHP 5.4


RobertP

Recommended Posts

  • 3 weeks later...

Well those who are used to MySQL will need to live with the fact that PDO does not have an equivalent method PDO::num_rows() to replace mysql_num_rows(). Its quite annoying, but can be easily overcome with the usage of 'SELECT COUNT' statement. As far as I know, 'SELECT COUNT' is more efficient than mysql_num_rows(), although it does take much more typing.

Link to comment
Share on other sites

Well those who are used to MySQL will need to live with the fact that PDO does not have an equivalent method PDO::num_rows() to replace mysql_num_rows(). Its quite annoying, but can be easily overcome with the usage of 'SELECT COUNT' statement. As far as I know, 'SELECT COUNT' is more efficient than mysql_num_rows(), although it does take much more typing.

 

Uh... http://www.php.net/manual/en/pdostatement.rowcount.php

Link to comment
Share on other sites

Well those who are used to MySQL will need to live with the fact that PDO does not have an equivalent method PDO::num_rows() to replace mysql_num_rows(). Its quite annoying, but can be easily overcome with the usage of 'SELECT COUNT' statement. As far as I know, 'SELECT COUNT' is more efficient than mysql_num_rows(), although it does take much more typing.

 

Uh... http://www.php.net/manual/en/pdostatement.rowcount.php

 

For most databases, PDOStatement::rowCount() does not return the number of rows affected by a SELECT statement. Instead, use PDO::query() to issue a SELECT COUNT(*) statement with the same predicates as your intended SELECT statement, then use PDOStatement::fetchColumn() to retrieve the number of rows that will be returned.

 

You can also just do count($result->fetchAll());

Link to comment
Share on other sites

That won't get you a count from a select, just of recently affected rows.

 

You can also just do count($result->fetchAll());

That's about the closest thing, however if you don't want to fetch all of the rows the select count will always be there for you. In a situation like this, one less query usually == better.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.