PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mysql/tests/mysql_query.php

http://github.com/facebook/hiphop-php
PHP | 106 lines | 81 code | 22 blank | 3 comment | 31 complexity | 6720810b2bce298a9e3a86e2ae1dcd36 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. include_once("connect.inc");
  3. $tmp = NULL;
  4. $link = NULL;
  5. if (!is_null($tmp = @mysql_query()))
  6. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  7. if (false !== ($tmp = @mysql_query($link)))
  8. printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  9. require('table.inc');
  10. if (NULL !== ($tmp = @mysql_query("SELECT 1 AS a", $link, "foo")))
  11. printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  12. if (false !== ($tmp = mysql_query('THIS IS NOT SQL', $link)))
  13. printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  14. if (false !== ($tmp = mysql_query("SELECT 'this is sql but with backslash g'\g", $link)))
  15. printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  16. if ((0 === mysql_errno($link)) || ('' == mysql_error($link)))
  17. printf("[006] mysql_errno()/mysql_error should return some error\n");
  18. if (!$res = mysql_query("SELECT 'this is sql but with semicolon' AS valid ; ", $link))
  19. printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));
  20. var_dump(mysql_fetch_assoc($res));
  21. mysql_free_result($res);
  22. if (!$res = mysql_query("SELECT 'a' AS ''", $link))
  23. printf("[007a] [%d] %s\n", mysql_errno($link), mysql_error($link));
  24. var_dump($tmp = mysql_fetch_assoc($res));
  25. var_dump($tmp[""]);
  26. mysql_free_result($res);
  27. if (false !== ($res = mysql_query("SELECT 'this is sql but with semicolon' AS valid ; SHOW VARIABLES", $link)))
  28. printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link));
  29. if (mysql_query('DROP PROCEDURE IF EXISTS p', $link)) {
  30. // let's try to play with stored procedures
  31. if (mysql_query('CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;', $link)) {
  32. $res = mysql_query('CALL p(@version)', $link);
  33. $res = mysql_query('SELECT @version AS p_version', $link);
  34. $tmp = mysql_fetch_assoc($res);
  35. if (!isset($tmp['p_version']) || ('' == $tmp['p_version'])) {
  36. printf("[009] Result seems wrong, dumping\n");
  37. var_dump($tmp);
  38. }
  39. if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp['p_version'])) {
  40. printf("[010] Expecting unicode string, dumping\n");
  41. var_dump($tmp);
  42. }
  43. mysql_free_result($res);
  44. } else {
  45. printf("[011] [%d] %s\n", mysql_errno($link), mysql_error($link));
  46. }
  47. mysql_query('DROP FUNCTION IF EXISTS f', $link);
  48. if (mysql_query('CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN ver_param;', $link)) {
  49. $res = mysql_query('SELECT f(VERSION()) AS f_version', $link);
  50. $tmp = mysql_fetch_assoc($res);
  51. if (!isset($tmp['f_version']) || ('' == $tmp['f_version'])) {
  52. printf("[012] Result seems wrong, dumping\n");
  53. var_dump($tmp);
  54. }
  55. if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp['f_version'])) {
  56. printf("[013] Expecting unicode string, dumping\n");
  57. var_dump($tmp);
  58. }
  59. mysql_free_result($res);
  60. } else {
  61. printf("[014] [%d] %s\n", mysql_errno($link), mysql_error($link));
  62. }
  63. }
  64. mysql_close($link);
  65. if (false !== ($tmp = mysql_query("SELECT id FROM test", $link)))
  66. printf("[011] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  67. print "done!";
  68. ?>
  69. <?php error_reporting(0); ?>
  70. <?php
  71. require_once('connect.inc');
  72. // connect + select_db
  73. if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
  74. printf("[clean] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  75. $host, $myhost, $user, $db, $port, $socket);
  76. }
  77. if (!mysql_query('DROP TABLE IF EXISTS test', $link)) {
  78. printf("[clean] Failed to drop test table: [%d] %s\n", mysql_errno($link), mysql_error($link));
  79. }
  80. /* MySQL server may not support this - ignore errors */
  81. @mysql_query('DROP PROCEDURE IF EXISTS p', $link);
  82. @mysql_query('DROP FUNCTION IF EXISTS f', $link);
  83. mysql_close($link);
  84. ?>