1--TEST-- 2MySQL PDOStatement->errorCode(); 3--EXTENSIONS-- 4pdo_mysql 5--SKIPIF-- 6<?php 7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 8MySQLPDOTest::skip(); 9$db = MySQLPDOTest::factory(); 10?> 11--FILE-- 12<?php 13 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 14 $db = MySQLPDOTest::factory(); 15 16 $db->exec('DROP TABLE IF EXISTS ihopeitdoesnotexist'); 17 18 printf("Testing emulated PS...\n"); 19 try { 20 $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1); 21 if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY)) 22 printf("[002] Unable to turn on emulated prepared statements\n"); 23 24 $stmt = $db->prepare('SELECT id FROM ihopeitdoesnotexist ORDER BY id ASC'); 25 $stmt->execute(); 26 var_dump($stmt->errorCode()); 27 28 29 } catch (PDOException $e) { 30 printf("[001] %s [%s] %s\n", 31 $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo())); 32 } 33 34 printf("Testing native PS...\n"); 35 try { 36 $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0); 37 if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY)) 38 printf("[004] Unable to turn off emulated prepared statements\n"); 39 40 $stmt = $db->prepare('SELECT id FROM ihopeitdoesnotexist ORDER BY id ASC'); 41 $stmt->execute(); 42 var_dump($stmt->errorCode()); 43 44 } catch (PDOException $e) { 45 printf("[003] %s [%s] %s\n", 46 $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo())); 47 } 48 49 print "done!"; 50?> 51--EXPECTF-- 52Testing emulated PS... 53 54Warning: PDOStatement::execute(): SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.ihopeitdoesnotexist' doesn't exist in %s on line %d 55string(5) "42S02" 56Testing native PS... 57 58Warning: PDO::prepare(): SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.ihopeitdoesnotexist' doesn't exist in %s on line %d 59 60Fatal error: Uncaught Error: Call to a member function execute() on false in %s:%d 61Stack trace: 62#0 {main} 63 thrown in %s on line %d 64