PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

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