mysql_unbuffered_query.phpt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. --TEST--
  2. mysql_unbuffered_query()
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. ?>
  8. --FILE--
  9. <?php
  10. include_once("connect.inc");
  11. $tmp = NULL;
  12. $link = NULL;
  13. if (false !== ($tmp = @mysql_unbuffered_query($link)))
  14. printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  15. require('table.inc');
  16. if (NULL !== ($tmp = @mysql_unbuffered_query("SELECT 1 AS a", $link, "foo")))
  17. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  18. if (false !== ($tmp = mysql_unbuffered_query('THIS IS NOT SQL', $link)))
  19. printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  20. if (false !== ($tmp = mysql_unbuffered_query("SELECT 'this is sql but with backslash g'\g", $link)))
  21. printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  22. if ((0 === mysql_errno($link)) || ('' == mysql_error($link)))
  23. printf("[005] mysql_errno()/mysql_error should return some error\n");
  24. if (!$res = mysql_unbuffered_query("SELECT 'this is sql but with semicolon' AS valid ; ", $link))
  25. printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
  26. var_dump(mysql_fetch_assoc($res));
  27. mysql_free_result($res);
  28. if (false !== ($res = mysql_unbuffered_query("SELECT 'this is sql but with semicolon' AS valid ; SHOW VARIABLES", $link)))
  29. printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));
  30. if (mysql_unbuffered_query('DROP PROCEDURE IF EXISTS p', $link)) {
  31. // let's try to play with stored procedures
  32. if (mysql_unbuffered_query('CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;', $link)) {
  33. $res = mysql_unbuffered_query('CALL p(@version)', $link);
  34. $res = mysql_unbuffered_query('SELECT @version AS p_version', $link);
  35. $tmp = mysql_fetch_assoc($res);
  36. if (!isset($tmp['p_version']) || ('' == $tmp['p_version'])) {
  37. printf("[008] Result seems wrong, dumping\n");
  38. var_dump($tmp);
  39. }
  40. if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp['p_version'])) {
  41. printf("[009] Expecting unicode string, dumping\n");
  42. var_dump($tmp);
  43. }
  44. mysql_free_result($res);
  45. } else {
  46. printf("[010] [%d] %s\n", mysql_errno($link), mysql_error($link));
  47. }
  48. mysql_unbuffered_query('DROP FUNCTION IF EXISTS f', $link);
  49. if (mysql_unbuffered_query('CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN ver_param;', $link)) {
  50. $res = mysql_unbuffered_query('SELECT f(VERSION()) AS f_version', $link);
  51. $tmp = mysql_fetch_assoc($res);
  52. if (!isset($tmp['f_version']) || ('' == $tmp['f_version'])) {
  53. printf("[011] Result seems wrong, dumping\n");
  54. var_dump($tmp);
  55. }
  56. if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp['f_version'])) {
  57. printf("[012] Expecting unicode string, dumping\n");
  58. var_dump($tmp);
  59. }
  60. mysql_free_result($res);
  61. } else {
  62. printf("[012] [%d] %s\n", mysql_errno($link), mysql_error($link));
  63. }
  64. }
  65. var_dump(mysql_unbuffered_query('INSERT INTO test(id) VALUES (100)', $link));
  66. var_dump($res = mysql_unbuffered_query('SELECT id FROM test', $link));
  67. var_dump(mysql_num_rows($res));
  68. mysql_close($link);
  69. if (false !== ($tmp = mysql_unbuffered_query("SELECT id FROM test", $link)))
  70. printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  71. print "done!";
  72. ?>
  73. --CLEAN--
  74. <?php
  75. require_once('connect.inc');
  76. // connect + select_db
  77. if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
  78. printf("[clean] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  79. $host, $myhost, $user, $db, $port, $socket);
  80. }
  81. if (!mysql_query('DROP TABLE IF EXISTS test', $link)) {
  82. printf("[clean] Failed to drop test table: [%d] %s\n", mysql_errno($link), mysql_error($link));
  83. }
  84. /* MySQL server may not support this - ignore errors */
  85. @mysql_query('DROP PROCEDURE IF EXISTS p', $link);
  86. @mysql_query('DROP FUNCTION IF EXISTS f', $link);
  87. mysql_close($link);
  88. ?>
  89. --EXPECTF--
  90. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  91. array(1) {
  92. [%u|b%"valid"]=>
  93. %unicode|string%(30) "this is sql but with semicolon"
  94. }
  95. bool(true)
  96. resource(%d) of type (mysql result)
  97. int(0)
  98. Notice: mysql_close(): Function called without first fetching all rows from a previous unbuffered query in %s on line %d
  99. Warning: mysql_unbuffered_query(): %d is not a valid MySQL-Link resource in %s on line %d
  100. done!