|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-03-29 16:20 UTC] alan at aondra dot com
Description:
------------
PDO does not support running multiple queries out of the box. Installed 7.3.3 x64 TS. This also goes back to at least 7.3.0.
Test script:
---------------
$db = new PDO($dsn, $username, $password, [
PDO::ATTR_EMULATE_PREPARES => true,
PDO::ATTR_AUTOCOMMIT => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_MULTI_STATEMENTS => true,
]);
// mysqlnd 5.0.12-dev - 20150407 - $Id: 7cc7cc96e675f6d72e5cf0f267f48e167c2abb23 $
echo $db->getAttribute(PDO::ATTR_CLIENT_VERSION) . PHP_EOL;
// PDOException#0: SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute
echo $db->getAttribute(PDO::MYSQL_ATTR_MULTI_STATEMENTS) . PHP_EOL;
$stmt = $db->query('SELECT 1; SELECT 2;');
// SELECT 1; SELECT 2;
echo $stmt->queryString . PHP_EOL;
Expected result:
----------------
I expect that the query be executed as multiple queries, with each result being a rowset, and each rowset having a non-zero number of rows.
Actual result:
--------------
An empty result, or a PDOException being thrown for multiple queries being incorrect syntax (depending on other configurations).
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 17:00:02 2025 UTC |
I haven't checked the flag and whether we could add explicit support, but pdo_mysql defaults to multi_statement mode as that is needed for calling stored procedures which users expected to work by default. <?php $dsn = 'mysql:host=127.0.0.1:3380'; $username = 'native'; $password = ''; $db = new PDO($dsn, $username, $password, [ PDO::ATTR_EMULATE_PREPARES => true, PDO::ATTR_AUTOCOMMIT => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_MULTI_STATEMENTS => true, ]); $stmt = $db->query('SELECT 1; SELECT 2;'); var_dump($stmt->fetchAll()); $stmt->nextRowset(); var_dump($stmt->fetchAll()); ?> array(1) { [0]=> array(2) { [1]=> string(1) "1" [2]=> string(1) "1" } } array(1) { [0]=> array(2) { [2]=> string(1) "2" [3]=> string(1) "2" } }