I have been trying to display number of rows from my db, but it displays 0 rows instead of 8 rows.
Here is my code:
$db_hostname=“127.0.0.1”;
$db_name="…";
$db_username="…";
$db_password=“dosso12345”;
try {
$pdo=new PDO("mysql:host=$db_hostname;db=$db_name", $db_username, $db_password);
echo "Connection established";
} catch (PDOException $e) {
echo 'Cannot connect to database';
exit;
}
PHP code:
<?php include_once 'connection.inc.php'; try { $sql='SELECT count(*) FROM images'; $result = $pdo->prepare($sql); $result->execute(); $count= $result->rowCount(); echo $count; $result->closeCursor(); catch (PDOException $e) { echo "Error in code".$e->getMessage(); } ?>