Bug #73299 [NEW]: Cannot change db with "use another_db" sql query
| From: | lubomir dot cvrk at webnode dot com | Date: | Wed, 12 Oct 2016 05:36:11 +0000 |
| Subject: | Bug #73299 [NEW]: Cannot change db with "use another_db" sql query | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-204620@lists.php.net to get a copy of this message | ||
From: lubomir dot cvrk at webnode dot com
Operating system: Linux, Windows
PHP version: 5.6.26
Package: PDO MySQL
Bug Type: Bug
Bug description:Cannot change db with "use another_db" sql query
Description:
------------
When \PDO::ATTR_EMULATE_PREPARES == false, and the initial connection is
created with "some_db" context, the PDO is unable to run the query for
changing the database (use another_db) and returns an error:
Array
(
[0] => HY000
[1] => 2014
[2] => 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.
)
Test script:
---------------
function test_pdo($prepares)
{
echo 'Testing PDO with \PDO::ATTR_EMULATE_PREPARES=' . ($prepares ?
'true' : 'false') . "\n\n";
$options[\PDO::ATTR_EMULATE_PREPARES] = $prepares;
$db = new
PDO('mysql:host=some.host.net;dbname=some_db;charset=utf8','user','password',$options);
$result = $db->query('use ms_system');
echo 'After PDO::query(use another_db): ';
echo $result === false ? 'PDO ERROR' : 'PDO is OK';
echo "\n";
$stmt = $db->prepare('use ms_system');
$result = $stmt->execute();
echo 'After PDO::prepare(use another_db); PDO::execute(): ';
if ($result === false) {
echo 'PDO ERROR - ' . print_r($stmt->errorInfo(), true);
} else {
echo 'PDO is OK';
}
echo "\n---------------------------------------------------\n\n";
}
echo '<xmp>'; test_pdo(true); test_pdo(false);
Expected result:
----------------
<xmp>Testing PDO with \PDO::ATTR_EMULATE_PREPARES=true
After PDO::query(use another_db): PDO is OK
After PDO::prepare(use another_db); PDO::execute(): PDO is OK
---------------------------------------------------
Testing PDO with \PDO::ATTR_EMULATE_PREPARES=false
After PDO::query(use another_db): PDO is OK
After PDO::prepare(use another_db); PDO::execute(): PDO is OK
---------------------------------------------------
--
Edit bug report at https://bugs.php.net/bug.php?id=73299&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73299&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73299&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73299&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73299&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73299&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73299&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73299&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73299&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73299&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73299&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73299&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73299&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73299&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73299&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73299&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73299&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73299&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73299&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73299&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73299&r=mysqlcfg