PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/bad/ext/pdo_mysql/tests/pdo_mysql_stmt_fetch_non_select.php

http://github.com/facebook/hiphop-php
PHP | 179 lines | 146 code | 28 blank | 5 comment | 55 complexity | af370d3f3059b01c11803136f91c4dee MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
  3. $db = MySQLPDOTest::factory();
  4. MySQLPDOTest::createTestTable($db);
  5. try {
  6. // Emulated PS first
  7. $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
  8. if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
  9. printf("[002] Unable to turn on emulated prepared statements\n");
  10. if (!is_object($stmt = $db->query('DESCRIBE test id')))
  11. printf("[003] Emulated PS, DESCRIBE failed, %s\n", var_export($db->errorInfo(), true));
  12. $describe = array();
  13. $valid = false;
  14. while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  15. $describe[] = $row;
  16. foreach ($row as $column => $value)
  17. if (isset($row['field']) && ($row['field'] == 'id'))
  18. $valid = true;
  19. }
  20. if (empty($describe))
  21. printf("[004] Emulated PS, DESCRIBE returned no results\n");
  22. else if (!$valid)
  23. printf("[005] Emulated PS, DESCRIBE, returned data seems wrong, dumping %s\n",
  24. var_export($describe, true));
  25. if (!is_object($stmt = $db->query('SHOW ENGINES')))
  26. printf("[006] Emulated PS, SHOW failed, %s\n", var_export($db->errorInfo(), true));
  27. $show = array();
  28. $valid = false;
  29. while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  30. $show[] = $row;
  31. foreach ($row as $column => $value)
  32. // MyISAM engine should be part of _every_ MySQL today
  33. if ($value == 'MyISAM')
  34. $valid = true;
  35. }
  36. if (empty($show))
  37. printf("[007] Emulated PS, SHOW returned no results\n");
  38. else if (!$valid)
  39. printf("[008] Emulated PS, SHOW data seems wrong, dumping %s\n",
  40. var_export($show, true));
  41. if (!is_object($stmt = $db->query("EXPLAIN SELECT id FROM test")))
  42. printf("[009] Emulated PS, EXPLAIN returned no results\n");
  43. $explain = array();
  44. while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
  45. $explain[] = $row;
  46. if (empty($explain))
  47. printf("[010] Emulated PS, EXPLAIN returned no results\n");
  48. // And now native PS
  49. $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
  50. if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
  51. printf("[011] Unable to turn off emulated prepared statements\n");
  52. $native_support = 'no';
  53. if ($db->exec("PREPARE mystmt FROM 'DESCRIBE test id'")) {
  54. $native_support = 'yes';
  55. $db->exec('DEALLOCATE PREPARE mystmt');
  56. }
  57. if (!is_object($stmt = $db->query('DESCRIBE test id')))
  58. printf("[012] Native PS (native support: %s), DESCRIBE failed, %s\n",
  59. $native_support,
  60. var_export($db->errorInfo(), true));
  61. $describe_native = array();
  62. $valid = false;
  63. while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  64. $describe_native[] = $row;
  65. foreach ($row as $column => $value)
  66. if (isset($row['field']) && ($row['field'] == 'id'))
  67. $valid = true;
  68. }
  69. if (empty($describe_native))
  70. printf("[013] Native PS (native support: %s), DESCRIBE returned no results\n",
  71. $native_support);
  72. else if (!$valid)
  73. printf("[014] Native PS (native support: %s), DESCRIBE, returned data seems wrong, dumping %s\n",
  74. $native_support,
  75. var_export($describe_native, true));
  76. if ($describe != $describe_native)
  77. printf("[015] Emulated and native PS (native support: %s) results of DESCRIBE differ: %s vs. %s\n",
  78. $native_support,
  79. var_export($describe, true),
  80. var_export($describe_native, true));
  81. $native_support = 'no';
  82. if ($db->exec("PREPARE mystmt FROM 'SHOW ENGINES'")) {
  83. $native_support = 'yes';
  84. $db->exec('DEALLOCATE PREPARE mystmt');
  85. }
  86. if (!is_object($stmt = $db->query('SHOW ENGINES')))
  87. printf("[016] Native PS (native support: %s), SHOW failed, %s\n",
  88. $native_support,
  89. var_export($db->errorInfo(), true));
  90. $show_native = array();
  91. $valid = false;
  92. while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  93. $show_native[] = $row;
  94. foreach ($row as $column => $value)
  95. // MyISAM engine should be part of _every_ MySQL today
  96. if ($value == 'MyISAM')
  97. $valid = true;
  98. }
  99. if (empty($show_native))
  100. printf("[017] Native PS (native support: %s), SHOW returned no results\n",
  101. $native_support);
  102. else if (!$valid)
  103. printf("[018] Native PS (native support: %s), SHOW data seems wrong, dumping %s\n",
  104. var_export($show_native, true));
  105. if ($show != $show_native)
  106. printf("Native PS (native support: %s) and emulated PS returned different data for SHOW: %s vs. %s\n",
  107. $native_support,
  108. var_export($show, true),
  109. var_export($show_native, true));
  110. $native_support = 'no';
  111. if ($db->exec("PREPARE mystmt FROM 'EXPLAIN SELECT id FROM test'")) {
  112. $native_support = 'yes';
  113. $db->exec('DEALLOCATE PREPARE mystmt');
  114. }
  115. if (!is_object($stmt = $db->query("EXPLAIN SELECT id FROM test")))
  116. printf("[012] Native PS (native support: %s), EXPLAIN failed, %s\n",
  117. $native_support,
  118. var_export($db->errorInfo(), true));
  119. $explain_native = array();
  120. while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
  121. $explain_native[] = $row;
  122. if (empty($explain_native))
  123. printf("[013] Native PS (native support: %s), EXPLAIN returned no results\n",
  124. $native_support);
  125. if ($explain != $explain_native)
  126. printf("Native PS (native support: %s) and emulated PS returned different data for EXPLAIN: %s vs. %s\n",
  127. $native_support,
  128. var_export($explain, true),
  129. var_export($explain_native, true));
  130. $stmt->execute();
  131. $explain_native = $stmt->fetchAll(PDO::FETCH_ASSOC);
  132. if ($explain != $explain_native)
  133. printf("Native PS (native support: %s) and emulated PS returned different data for EXPLAIN: %s vs. %s\n",
  134. $native_support,
  135. var_export($explain, true),
  136. var_export($explain_native, true));
  137. $stmt->execute();
  138. $stmt->execute();
  139. // libmysql needs this - otherwise we get a 2015 error
  140. if (!MYSQLPDOTest::isPDOMySQLnd())
  141. $stmt->fetchAll(PDO::FETCH_ASSOC);
  142. } catch (PDOException $e) {
  143. printf("[001] %s [%s] %s\n",
  144. $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
  145. }
  146. print "done!\n";
  147. ?>
  148. <?php
  149. require dirname(__FILE__) . '/mysql_pdo_test.inc';
  150. MySQLPDOTest::dropTestTable();
  151. ?>