sql row count php pdo
snippet in php

sql row count php pdo


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

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

number of rows in a mysql table pdo


//Instantiate the PDO object and connect to MySQL.
$pdo = new PDO(
//The COUNT SQL statement that we will use.
$sql = "SELECT COUNT(*) AS num FROM users";
//Prepare the COUNT SQL statement.
$stmt = $pdo->prepare($sql);
//Execute the COUNT statement.
//Fetch the row that MySQL returned.
$row = $stmt->fetch(PDO::FETCH_ASSOC);
//The $row array will contain "num". Print it out.
echo $row['num'] . ' users exist.';