Web applications often need to execute multiple SQL statements in a single round trip—for example, inserting a parent record followed by several child records. While some native drivers supported multi-query, PDO 1.x lacked a standardized interface. PDO 2.0 introduces the multiQuery() method, which executes a batch of semicolon-separated statements and returns an iterator of result sets.
$pdo->beginTransaction(); try // Perform database operations $pdo->exec('INSERT INTO users (name, email) VALUES ("Jane", "jane@example.com")'); $pdo->exec('INSERT INTO orders (user_id, total) VALUES (LAST_INSERT_ID(), 100.00)'); $pdo->commit(); catch (PDOException $e) $pdo->rollBack();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) // Process without holding entire result set in PHP memory
$generator = function () for ($i = 0; $i < 1_000_000; $i++) yield ['INFO', "Message $i"];
class User public UserStatus $status;
Web applications often need to execute multiple SQL statements in a single round trip—for example, inserting a parent record followed by several child records. While some native drivers supported multi-query, PDO 1.x lacked a standardized interface. PDO 2.0 introduces the multiQuery() method, which executes a batch of semicolon-separated statements and returns an iterator of result sets.
$pdo->beginTransaction(); try // Perform database operations $pdo->exec('INSERT INTO users (name, email) VALUES ("Jane", "jane@example.com")'); $pdo->exec('INSERT INTO orders (user_id, total) VALUES (LAST_INSERT_ID(), 100.00)'); $pdo->commit(); catch (PDOException $e) $pdo->rollBack();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) // Process without holding entire result set in PHP memory
$generator = function () for ($i = 0; $i < 1_000_000; $i++) yield ['INFO', "Message $i"];
class User public UserStatus $status;