1--TEST-- 2MySQL PDO->exec(), SELECT 3--SKIPIF-- 4<?php 5require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc'); 6require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 7MySQLPDOTest::skip(); 8?> 9--FILE-- 10<?php 11 function exec_and_count($offset, &$db, $sql, $exp) { 12 13 try { 14 15 $ret = $db->exec($sql); 16 if ($ret !== $exp) { 17 printf("[%03d] Expecting '%s'/%s got '%s'/%s when running '%s', [%s] %s\n", 18 $offset, $exp, gettype($exp), $ret, gettype($ret), $sql, 19 $db->errorCode(), implode(' ', $db->errorInfo())); 20 return false; 21 } 22 23 } catch (PDOException $e) { 24 printf("[%03d] '%s' has failed, [%s] %s\n", 25 $offset, $sql, $db->errorCode(), implode(' ', $db->errorInfo())); 26 return false; 27 } 28 29 return true; 30 } 31 32 require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 33 $db = MySQLPDOTest::factory(); 34 MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db)); 35 36 /* affected rows related */ 37 try { 38 39 exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0); 40 exec_and_count(3, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0); 41 exec_and_count(4, $db, "INSERT INTO test(id, col1) VALUES (1, 'a')", 1); 42 // question is: will the result set be cleaned up, will it be possible to run more queries on the line? 43 // buffered or unbuffered does not matter! 44 $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); 45 exec_and_count(5, $db, 'SELECT id FROM test', 0); 46 exec_and_count(6, $db, "INSERT INTO test(id, col1) VALUES (2, 'b')", 1); 47 48 } catch (PDOException $e) { 49 printf("[001] %s, [%s] %s\n", 50 $e->getMessage(), 51 $db->errorCode(), implode(' ', $db->errorInfo())); 52 } 53 54 print "done!"; 55?> 56--CLEAN-- 57<?php 58require dirname(__FILE__) . '/mysql_pdo_test.inc'; 59$db = MySQLPDOTest::factory(); 60@$db->exec('DROP TABLE IF EXISTS test'); 61?> 62--EXPECTF-- 63Warning: PDO::exec(): 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 %s on line %d 64[006] Expecting '1'/integer got ''/boolean when running 'INSERT INTO test(id, col1) VALUES (2, 'b')', [HY000] HY000 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. 65done! 66