devxtec Posted January 29, 2009 Share Posted January 29, 2009 I am trying to figure out how I can get the number of rows returned by a fetch. Is there an equivalent of mysql_num_rows() that comes with PDO? I noticed PDOStatement->rowCount(), however; on select statements this is not a guaranteed way of getting back the number of rows returned by the statement as this behavior is not guaranteed for all databases. Anyone have any ideas on how to go about getting the number of rows? Link to comment https://forums.phpfreaks.com/topic/142995-pdo-equivalent-of-mysql_num_rows/ Share on other sites More sharing options...
printf Posted January 29, 2009 Share Posted January 29, 2009 PDO::query("SELECT COUNT(*)"... then the query of what you want to count ); PDOStatement::fetchColumn(); that's the proper way using PDO for all database types... What I am trying to tell you, is that you should do the SELECT COUNT(*) first and if PDOStatement::fetchColumn(); returns greater than > 0, then you would do the actually query and loop those results. That's the proper way of doing database SELECT(s). Sure it not the mysql/php way, but it is the way one should always do it when using a DB abstracting layer... Link to comment https://forums.phpfreaks.com/topic/142995-pdo-equivalent-of-mysql_num_rows/#findComment-749820 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.