003.phpt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. --TEST--
  2. mysql_fetch_object
  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. class class24 {
  12. function __construct() {
  13. echo __METHOD__ . "\n";
  14. }
  15. }
  16. $data = array("one", "two", "three");
  17. if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
  18. printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  19. $host, $user, $db, $port, $socket);
  20. if (!mysql_query('DROP TABLE IF EXISTS test', $link))
  21. printf("[002] [%d] %s\n", mysql_errno($link), mysql_error($link));
  22. if (!mysql_query("CREATE TABLE test(a varchar(10))", $link))
  23. printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
  24. foreach ($data as $str) {
  25. if (!mysql_query(sprintf("INSERT INTO test VALUES('%s')", $str), $link))
  26. printf("[004 - %s] [%d] %s\n", $str, mysql_errno($link), mysql_error($link));
  27. }
  28. echo "==stdClass==\n";
  29. if (!$res = mysql_query("SELECT a FROM test", $link))
  30. printf("[005] [%d] %s\n", mysql_errno($link), mysql_error($link));
  31. while ($obj = mysql_fetch_object($res)) {
  32. var_dump($obj);
  33. }
  34. mysql_free_result($res);
  35. echo "==class24==\n";
  36. if (!$res = mysql_query("SELECT a FROM test", $link))
  37. printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
  38. while ($obj = mysql_fetch_object($res, 'class24')) {
  39. var_dump($obj);
  40. }
  41. mysql_free_result($res);
  42. mysql_close($link);
  43. print "done!";
  44. ?>
  45. --CLEAN--
  46. <?php
  47. require_once("clean_table.inc");
  48. ?>
  49. --EXPECTF--
  50. 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
  51. ==stdClass==
  52. object(stdClass)#%d (1) {
  53. [%u|b%"a"]=>
  54. %unicode|string%(3) "one"
  55. }
  56. object(stdClass)#%d (1) {
  57. [%u|b%"a"]=>
  58. %unicode|string%(3) "two"
  59. }
  60. object(stdClass)#%d (1) {
  61. [%u|b%"a"]=>
  62. %unicode|string%(5) "three"
  63. }
  64. ==class24==
  65. class24::__construct
  66. object(class24)#%d (1) {
  67. [%u|b%"a"]=>
  68. %unicode|string%(3) "one"
  69. }
  70. class24::__construct
  71. object(class24)#%d (1) {
  72. [%u|b%"a"]=>
  73. %unicode|string%(3) "two"
  74. }
  75. class24::__construct
  76. object(class24)#%d (1) {
  77. [%u|b%"a"]=>
  78. %unicode|string%(5) "three"
  79. }
  80. done!