php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77823 Constant MYSQL_ATTR_MULTI_STATEMENTS not supported
Submitted: 2019-03-29 16:20 UTC Modified: 2019-04-01 15:43 UTC
From: alan at aondra dot com Assigned:
Status: Open Package: PDO MySQL
PHP Version: 7.3.3 OS: Windows 10 x64
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-01 15:43 UTC] johannes@php.net
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"
  }
}
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 02:01:25 2019 UTC