020 555 1111
  • Old fashion, modular, procedural PHP plus some scaffolding techniques to allow it to mimic MVC simplicity.
  • A quick reference to help you find in PHP maze what needs to be done and how to do it.
  • Learn a PHP Object Oriented Programming by building a live discussion forum application.
  • MVC - Model View Controller - real life, easy reference and application.
This product has options, take a look at them and select ones you like the most.
Options are displayed under image section.

PDO way of counting rows (num_rows)
[MySQL PDO example]

PDO (PHP Data Objects) way to count affected rows (num_rows).

It iss a bit curious for SELECT query.

 

php.net way of counting SELECTed results

//SELECT query:

$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.";
    }
}

$res = null;
$conn = null;


 

some other way of counting SELECTed results

$sql = 'SELECT * FROM users WHERE point< :point';
$sth = $this->db->prepare($sql);

/* Bindparam to point */
$sth->execute(Array(':point' => 20));
$data = $sth->fetchAll();

/* Get the number of rows that match the SELECT statement */
$count = sizeof($data); /* or count($data) */

/* Print how many records found */
echo $count.' record found';

/* List data */
if ($count > 0) { 
    foreach ($data as $value) {
        echo $value['Name'].'<br />';
     }
  } 
}

 

 

and yet another way to count SELECTed

    $statement = $dbh->prepare('SELECT FROM fruit');
    $statement->execute();
    $count = $statement->rowCount();

 

 

php.net way of counting results

//DELETE, INSERT, or UPDATE

/* Delete all rows from the FRUIT table */
$del = $dbh->prepare('DELETE FROM fruit');
$del->execute();

/* Return number of rows that were deleted */
print("Return number of rows that were deleted:\n");
$count = $del->rowCount();
print("Deleted $count rows.\n");