处理来自PDO多查询的结果行

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?

Do not add complexity out of nowhere and you always will have convenient and predictable result

$db = new PDO("mysql:host=localhost;dbname=map1", 'root', 'root');
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

$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');";
$db->exec($sql);

$sql = "SELECT * FROM car";
$stmt = $db->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "resultamount: ".count($results);