bug34810.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. --TEST--
  2. Bug #34810 (mysqli::init() and others use wrong $this pointer without checks)
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. class DbConnection {
  12. public function connect() {
  13. require_once("connect.inc");
  14. /* Pass false as $connect_flags cannot be accessed via globals. */
  15. $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket, false);
  16. var_dump($link);
  17. $link = mysqli_init();
  18. var_dump($link);
  19. $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket, false);
  20. $mysql->query("DROP TABLE IF EXISTS test_warnings");
  21. $mysql->query("CREATE TABLE test_warnings (a int not null)");
  22. $mysql->query("SET sql_mode=''");
  23. $mysql->query("INSERT INTO test_warnings VALUES (1),(2),(NULL)");
  24. $warning = $mysql->get_warnings();
  25. if (!$warning)
  26. printf("[001] No warning!\n");
  27. if ($warning->errno == 1048 || $warning->errno == 1253) {
  28. /* 1048 - Column 'a' cannot be null, 1263 - Data truncated; NULL supplied to NOT NULL column 'a' at row */
  29. if ("HY000" != $warning->sqlstate)
  30. printf("[003] Wrong sql state code: %s\n", $warning->sqlstate);
  31. if ("" == $warning->message)
  32. printf("[004] Message string must not be empty\n");
  33. } else {
  34. printf("[002] Empty error message!\n");
  35. var_dump($warning);
  36. }
  37. }
  38. }
  39. $db = new DbConnection();
  40. $db->connect();
  41. echo "Done\n";
  42. ?>
  43. --CLEAN--
  44. <?php
  45. require_once("connect.inc");
  46. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  47. printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  48. if (!mysqli_query($link, "DROP TABLE IF EXISTS test_warnings"))
  49. printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  50. mysqli_close($link);
  51. ?>
  52. --EXPECTF--
  53. object(mysqli)#%d (%d) {
  54. ["affected_rows"]=>
  55. int(0)
  56. ["client_info"]=>
  57. string(%d) "%s"
  58. ["client_version"]=>
  59. int(%d)
  60. ["connect_errno"]=>
  61. int(0)
  62. ["connect_error"]=>
  63. NULL
  64. ["errno"]=>
  65. int(0)
  66. ["error"]=>
  67. string(0) ""
  68. ["error_list"]=>
  69. array(0) {
  70. }
  71. ["field_count"]=>
  72. int(0)
  73. ["host_info"]=>
  74. string(%d) "%s"
  75. ["info"]=>
  76. NULL
  77. ["insert_id"]=>
  78. int(0)
  79. ["server_info"]=>
  80. string(%d) "%s"
  81. ["server_version"]=>
  82. int(%d)
  83. ["sqlstate"]=>
  84. string(5) "00000"
  85. ["protocol_version"]=>
  86. int(10)
  87. ["thread_id"]=>
  88. int(%d)
  89. ["warning_count"]=>
  90. int(0)
  91. }
  92. object(mysqli)#%d (%d) {
  93. ["client_info"]=>
  94. string(%d) "%s"
  95. ["client_version"]=>
  96. int(%d)
  97. ["connect_errno"]=>
  98. int(0)
  99. ["connect_error"]=>
  100. NULL
  101. ["errno"]=>
  102. int(0)
  103. ["error"]=>
  104. string(0) ""
  105. }
  106. Done