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: 2021-03-18 16:57 UTC
From: alan at aondra dot com Assigned: cmb (profile)
Status: Not a bug Package: PDO MySQL
PHP Version: 7.3.3 OS: Windows 10 x64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alan at aondra dot com
New email:
PHP Version: OS:

 

 [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"
  }
}
 [2021-03-18 16:57 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-03-18 16:57 UTC] cmb@php.net
From the PHP manual[1]:

| Note, this constant can only be used in the driver_options array
| when constructing a new database handle.

So this works as advertized.

[1] <https://www.php.net/manual/en/ref.pdo-mysql.php#pdo-mysql.constants>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 09:01:30 2024 UTC