1--TEST-- 2MySQL PDOStatement->execute()/fetch(), Non-SELECT 3--EXTENSIONS-- 4pdo_mysql 5--SKIPIF-- 6<?php 7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 8MySQLPDOTest::skip(); 9?> 10--FILE-- 11<?php 12 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 13 $db = MySQLPDOTest::factory(); 14 MySQLPDOTest::createTestTable($db); 15 16 try { 17 18 // Emulated PS first 19 $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1); 20 if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY)) 21 printf("[002] Unable to turn on emulated prepared statements\n"); 22 23 if (!is_object($stmt = $db->query('DESCRIBE test id'))) 24 printf("[003] Emulated PS, DESCRIBE failed, %s\n", var_export($db->errorInfo(), true)); 25 26 $describe = array(); 27 $valid = false; 28 while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 29 $describe[] = $row; 30 foreach ($row as $column => $value) 31 if (isset($row['field']) && ($row['field'] == 'id')) 32 $valid = true; 33 } 34 if (empty($describe)) 35 printf("[004] Emulated PS, DESCRIBE returned no results\n"); 36 else if (!$valid) 37 printf("[005] Emulated PS, DESCRIBE, returned data seems wrong, dumping %s\n", 38 var_export($describe, true)); 39 40 if (!is_object($stmt = $db->query('SHOW ENGINES'))) 41 printf("[006] Emulated PS, SHOW failed, %s\n", var_export($db->errorInfo(), true)); 42 43 $show = array(); 44 $valid = false; 45 while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 46 $show[] = $row; 47 foreach ($row as $column => $value) 48 // MyISAM engine should be part of _every_ MySQL today 49 if ($value == 'MyISAM') 50 $valid = true; 51 } 52 if (empty($show)) 53 printf("[007] Emulated PS, SHOW returned no results\n"); 54 else if (!$valid) 55 printf("[008] Emulated PS, SHOW data seems wrong, dumping %s\n", 56 var_export($show, true)); 57 58 if (!is_object($stmt = $db->query("EXPLAIN SELECT id FROM test"))) 59 printf("[009] Emulated PS, EXPLAIN returned no results\n"); 60 61 $explain = array(); 62 while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) 63 $explain[] = $row; 64 65 if (empty($explain)) 66 printf("[010] Emulated PS, EXPLAIN returned no results\n"); 67 68 // And now native PS 69 $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0); 70 if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY)) 71 printf("[011] Unable to turn off emulated prepared statements\n"); 72 73 $native_support = 'no'; 74 if ($db->exec("PREPARE mystmt FROM 'DESCRIBE test id'")) { 75 $native_support = 'yes'; 76 $db->exec('DEALLOCATE PREPARE mystmt'); 77 } 78 79 if (!is_object($stmt = $db->query('DESCRIBE test id'))) 80 printf("[012] Native PS (native support: %s), DESCRIBE failed, %s\n", 81 $native_support, 82 var_export($db->errorInfo(), true)); 83 84 $describe_native = array(); 85 $valid = false; 86 while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 87 $describe_native[] = $row; 88 foreach ($row as $column => $value) 89 if (isset($row['field']) && ($row['field'] == 'id')) 90 $valid = true; 91 } 92 if (empty($describe_native)) 93 printf("[013] Native PS (native support: %s), DESCRIBE returned no results\n", 94 $native_support); 95 else if (!$valid) 96 printf("[014] Native PS (native support: %s), DESCRIBE, returned data seems wrong, dumping %s\n", 97 $native_support, 98 var_export($describe_native, true)); 99 100 if ($describe != $describe_native) 101 printf("[015] Emulated and native PS (native support: %s) results of DESCRIBE differ: %s vs. %s\n", 102 $native_support, 103 var_export($describe, true), 104 var_export($describe_native, true)); 105 106 107 $native_support = 'no'; 108 if ($db->exec("PREPARE mystmt FROM 'SHOW ENGINES'")) { 109 $native_support = 'yes'; 110 $db->exec('DEALLOCATE PREPARE mystmt'); 111 } 112 113 if (!is_object($stmt = $db->query('SHOW ENGINES'))) 114 printf("[016] Native PS (native support: %s), SHOW failed, %s\n", 115 $native_support, 116 var_export($db->errorInfo(), true)); 117 118 $show_native = array(); 119 $valid = false; 120 while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 121 $show_native[] = $row; 122 foreach ($row as $column => $value) 123 // MyISAM engine should be part of _every_ MySQL today 124 if ($value == 'MyISAM') 125 $valid = true; 126 } 127 if (empty($show_native)) 128 printf("[017] Native PS (native support: %s), SHOW returned no results\n", 129 $native_support); 130 else if (!$valid) 131 printf("[018] Native PS (native support: %s), SHOW data seems wrong, dumping %s\n", 132 var_export($show_native, true)); 133 134 if ($show != $show_native) 135 printf("Native PS (native support: %s) and emulated PS returned different data for SHOW: %s vs. %s\n", 136 $native_support, 137 var_export($show, true), 138 var_export($show_native, true)); 139 140 $native_support = 'no'; 141 if ($db->exec("PREPARE mystmt FROM 'EXPLAIN SELECT id FROM test'")) { 142 $native_support = 'yes'; 143 $db->exec('DEALLOCATE PREPARE mystmt'); 144 } 145 146 if (!is_object($stmt = $db->query("EXPLAIN SELECT id FROM test"))) 147 printf("[012] Native PS (native support: %s), EXPLAIN failed, %s\n", 148 $native_support, 149 var_export($db->errorInfo(), true)); 150 151 $explain_native = array(); 152 while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) 153 $explain_native[] = $row; 154 155 if (empty($explain_native)) 156 printf("[013] Native PS (native support: %s), EXPLAIN returned no results\n", 157 $native_support); 158 159 if ($explain != $explain_native) 160 printf("Native PS (native support: %s) and emulated PS returned different data for EXPLAIN: %s vs. %s\n", 161 $native_support, 162 var_export($explain, true), 163 var_export($explain_native, true)); 164 165 $stmt->execute(); 166 $explain_native = $stmt->fetchAll(PDO::FETCH_ASSOC); 167 if ($explain != $explain_native) 168 printf("Native PS (native support: %s) and emulated PS returned different data for EXPLAIN: %s vs. %s\n", 169 $native_support, 170 var_export($explain, true), 171 var_export($explain_native, true)); 172 173 $stmt->execute(); 174 $stmt->execute(); 175 // libmysql needs this - otherwise we get a 2015 error 176 if (!MYSQLPDOTest::isPDOMySQLnd()) 177 $stmt->fetchAll(PDO::FETCH_ASSOC); 178 179 } catch (PDOException $e) { 180 printf("[001] %s [%s] %s\n", 181 $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo())); 182 } 183 184 print "done!\n"; 185?> 186--CLEAN-- 187<?php 188require __DIR__ . '/mysql_pdo_test.inc'; 189MySQLPDOTest::dropTestTable(); 190?> 191--EXPECT-- 192done! 193