1--TEST-- 2MySQL PDO->prepare() and 1295 (ER_UNSUPPORTED_PS) 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// Run test only locally - not against remote hosts 10$db = MySQLPDOTest::factory(); 11$stmt = $db->query('SELECT USER() as _user'); 12$row = $stmt->fetch(PDO::FETCH_ASSOC); 13$tmp = explode('@', $row['_user']); 14if (count($tmp) < 2) 15 die("skip Cannot detect if test is run against local or remote database server"); 16if (($tmp[1] !== 'localhost') && ($tmp[1] !== '127.0.0.1')) 17 die("skip Test cannot be run against remote database server"); 18 19?> 20--FILE-- 21<?php 22 function exec_and_count($offset, &$db, $sql, $exp) { 23 24 try { 25 26 $ret = $db->exec($sql); 27 if ($ret !== $exp) { 28 printf("[%03d] Expecting '%s'/%s got '%s'/%s when running '%s', [%s] %s\n", 29 $offset, $exp, gettype($exp), $ret, gettype($ret), $sql, 30 $db->errorCode(), implode(' ', $db->errorInfo())); 31 return false; 32 } 33 34 } catch (PDOException $e) { 35 36 if (42000 == $db->errorCode()) { 37 // Error: 1148 SQLSTATE: 42000 (ER_NOT_ALLOWED_COMMAND) 38 // Load data infile not allowed 39 return false; 40 } 41 42 printf("[%03d] '%s' has failed, [%s] %s\n", 43 $offset, $sql, $db->errorCode(), implode(' ', $db->errorInfo())); 44 return false; 45 } 46 47 return true; 48 } 49 50 require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 51 $db = MySQLPDOTest::factory(); 52 // Run with native PS. 53 // The test is about checking the fallback to emulation 54 $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); 55 MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db)); 56 57 /* affected rows related */ 58 try { 59 60 exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0); 61 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); 62 63 $stmt = $db->query("SHOW VARIABLES LIKE 'secure_file_priv'"); 64 if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) { 65 $filename = $row['value'] . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv"; 66 } else { 67 $filename = MySQLPDOTest::getTempDir() . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv"; 68 } 69 70 $fp = fopen($filename, "w"); 71 fwrite($fp, b"1;foo\n"); 72 fwrite($fp, b"2;bar"); 73 fclose($fp); 74 75 // This should fail, the PS protocol should not support it. 76 // mysqlnd will give 2014 as a follow-up of the fallback logic 77 // libmysql will give a little more precise 2030 error code 78 // However, you get an error and the big question is what happens to the line 79 $stmt = $db->prepare(sprintf("LOAD DATA INFILE %s INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'", $db->quote($filename))); 80 if (!$stmt->execute()) { 81 printf("[004] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true)); 82 } 83 84 // Check the line 85 $stmt = $db->query("SELECT 1 as 'one'"); 86 if ($stmt->errorCode() != '0000') { 87 printf("[005] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true)); 88 } else { 89 $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); 90 if (!isset($rows[0]['one']) || $rows[0]['one'] != 1) 91 printf("[006] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true)); 92 } 93 94 unlink($filename); 95 96 } catch (PDOException $e) { 97 printf("[001] %s, [%s] %s (%s)\n", 98 $e->getMessage(), 99 $db->errorCode(), 100 implode(' ', $db->errorInfo()), 101 (isset($stmt)) ? implode(' ', $stmt->errorInfo()) : 'N/A'); 102 } 103 104 print "done!"; 105?> 106--CLEAN-- 107<?php 108require dirname(__FILE__) . '/mysql_pdo_test.inc'; 109MySQLPDOTest::dropTestTable(); 110?> 111--EXPECTF-- 112Warning: PDOStatement::execute(): SQLSTATE[HY000]: General error: %s in %s on line %d 113[004] [0] array ( 114 0 => 'HY000', 115 1 => %d, 116 2 => %s, 117) 118done!