php pdo rowcount code example
Example 1: sql row count php pdo
<?php
$del = $dbh->prepare('DELETE FROM fruit');
$del->execute();
print("Return number of rows that were deleted:\n");
$count = $del->rowCount();
print("Deleted $count rows.\n");
?>
Example 2: mysql rowcount php
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows Zeilen\n";
?>
Example 3: number of rows in a mysql table pdo
$pdo = new PDO(
'mysql:host=127.0.0.1;dbname=my_database',
'username',
'password'
);
$sql = "SELECT COUNT(*) AS num FROM users";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo $row['num'] . ' users exist.';