My code:
$pdo = new PDO('mysql:host=localhost; dbname=test', 'root', 'password');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
...
$count = $pdo->query('SELECT COUNT(*) FROM myTable');
I’m trying to count all records in myTable and store that number as $count. How can I make this happen?
I get this message: Object of class PDOStatement could not be converted to int. To my understanding, it is not an int.
Actually, that query will return a PDO statement. Then you can use that statement to get the item of interest.
This gets the statement from your query, then gets the first row (the only row from this query) and then stores the count, $result[0], into a variable named $count.