code derived from: PDO support for multiple queries (PDO_MYSQL, PDO_MYSQLND)
$db = new PDO("mysql:host=localhost;dbname=map1", 'root', 'root');
$sql = "
DROP TABLE IF EXISTS car;
CREATE TEMPORARY TABLE car (name (varchar 300), type (varchar 300));
INSERT INTO car(name, type) VALUES ('car1', 'coupe');
INSERT INTO car(name, type) VALUES ('car2', 'coupe');
SELECT * FROM car;
";
try {
$stmt = $db->prepare($sql);
$stmt->execute();
$query_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
catch (PDOException $e)
{
echo $e->getMessage();
die();
}
for ($i = 0; $i < count($query_results); $i++) {
echo $query_results[$i]['name']."</br>";
}
echo "resultamount: ".count($query_results);
the result amount for this query returns 0 (and the loop, of course, does not initiate). how do I fix this so that 2 rows are returned?