Hey friend!

You can use the PDOStatement::RowCount, but there is a problem (extracted from the PHP Manual, http://php.net/manual/en/pdostatement.rowcount.php): PDOStatement->rowCount - Returns the number of rows affected by the last SQL statement. If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.

You should test if the expected behavior happens with this method, or use the method below (less elegant):
$sql = "SELECT COUNT(*) FROM fruit WHERE calories > 100";
if ($res = $conn->query($sql)) {

    /* Check the number of rows that match the SELECT statement */
  if ($res->fetchColumn() > 0) {

/* Issue the real SELECT statement and work with the results */
         $sql = "SELECT name FROM fruit WHERE calories > 100";
       foreach ($conn->query($sql) as $row) {
           print "Name: " .  $row['NAME'] . "\n";
         }
    }
    /* No rows matched -- do something else */
  else {
      print "No rows matched the query.";
    }
}


Best regards,
Adriano Laranjeira.
> > > > > > > > > On Fri, 4 Mar 2011 07:30:51 -0500
"Ron Piggott" <ron.pigg...@actsministries.org> wrote:

When I used Prepared Statements how do I check for the # of rows found (Equal to mysql_numrows )?

IE Following the command:

$stmt->execute() or die(print_r($stmt->errorInfo(), true));

Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to