Bug #71145 [Com]: Multiple statements in init command triggers unbuffered query error

From: Date: Thu, 17 Dec 2015 04:40:11 +0000
Subject: Bug #71145 [Com]: Multiple statements in init command triggers unbuffered query error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197952@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71145&edit=1 ID: 71145 Comment by: danack@php.net Reported by: php at ontheroad dot net dot nz Summary: Multiple statements in init command triggers unbuffered query error Status: Open Type: Bug Package: PDO MySQL Operating System: Amazon Linux PHP Version: 5.6.16 Block user comment: N Private report: N New Comment: Hi, I will leave it to someone else to comment on whether what you are doing is supposed to work or not, but you can combine the SET commands into a single comma separated query, according to the MySQL manual like: SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci, SESSION sql_mode=traditional; Thus removing the need for multiple queries for your use-case. Previous Comments: ------------------------------------------------------------------------ [2015-12-17 04:03:13] php at ontheroad dot net dot nz Description: ------------ Using an PDO::MYSQL_ATTR_INIT_COMMAND with multiple statements separated by a semicolon triggers "General error: 2014 Cannot execute queries while other unbuffered queries are active.". The example below shows my situation. I want to ensure that UTF8 is handled correctly *and* enforce more strict MySQL behaviour, but it seems I can only set one or the other without triggering this bug. The application I've ran across this is being upgraded from PHP 5.4 using the old mysql library to PHP 5.6 with mysqlnd. Versions * PHP 5.6.14 * phpinfo() mysql Client API version => mysqlnd 5.0.11-dev * Amazon Linux mysql lib - php56-mysqlnd-5.6.14-1.119.amzn1.x86_64 Test script: --------------- <?php $options = array( PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, // This is the default, but here to be explicit PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;SET SESSION sql_mode=traditional', ); $dbo = new PDO( 'mysql:host=myhost.rds.amazonaws.com;port=3306;dbname=mydb;', 'user', 'password', $options ); $dbo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $dbo->prepare('SELECT foo FROM bar'); $stmt->execute(); Expected result: ---------------- Statement prepared and executed. Actual result: -------------- PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.' in /home/foo/minimum.php:18 Stack trace: #0 /home/foo/minimum.php(18): PDOStatement->execute() #1 {main} thrown in /home/foo/minimum.php on line 18 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71145&edit=1

« previous php.bugs (#197952) next »