mysqli_options_init_command.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. --TEST--
  2. mysqli_options()
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. <?php require_once('skipifemb.inc'); ?>
  10. --FILE--
  11. <?php
  12. /* see mysqli.c for details */
  13. require_once("connect.inc");
  14. if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)))
  15. printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  16. $host, $user, $db, $port, $socket);
  17. /* TODO: test more options */
  18. if (!mysqli_query($link, "DROP TABLE IF EXISTS test") ||
  19. !mysqli_query($link, sprintf("CREATE TABLE test(id INT) ENGINE = %s\n", $engine)) ||
  20. !mysqli_query($link, "INSERT INTO test(id) VALUES (1)"))
  21. printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  22. if (!$res = mysqli_query($link, "SELECT COUNT(id) AS _num_rows FROM test"))
  23. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  24. $row = mysqli_fetch_assoc($res);
  25. mysqli_free_result($res);
  26. if ($row['_num_rows'] != 1)
  27. printf("[003] Expecting 1 got %s\n", $row['_num_rows']);
  28. mysqli_close($link);
  29. $link = mysqli_init();
  30. if (true !== mysqli_options($link, MYSQLI_INIT_COMMAND, "INSERT INTO test(id) VALUES (2)"))
  31. printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  32. if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket))
  33. printf("[005] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  34. $host, $user, $db, $port, $socket);
  35. if (!$res = mysqli_query($link, "SELECT COUNT(id) AS _num_rows FROM test"))
  36. printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  37. $row = mysqli_fetch_assoc($res);
  38. mysqli_free_result($res);
  39. if ($row['_num_rows'] != 2)
  40. printf("[007] Expecting 1 got %s\n", $row['_num_rows']);
  41. mysqli_close($link);
  42. $link = mysqli_init();
  43. if (true !== mysqli_options($link, MYSQLI_INIT_COMMAND, "INSERT INTO test(i_do_no_exist) VALUES (2)"))
  44. printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  45. mysqli_close($link);
  46. $link = mysqli_init();
  47. if (true !== mysqli_options($link, MYSQLI_INIT_COMMAND, "INSERT INTO test(i_do_no_exist) VALUES (2)"))
  48. printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  49. if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket))
  50. printf("[010] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  51. $host, $user, $db, $port, $socket);
  52. print "done!";
  53. ?>
  54. --CLEAN--
  55. <?php
  56. require_once("clean_table.inc");
  57. ?>
  58. --EXPECTF--
  59. Warning: mysqli_real_connect(): (%s/%d): %s in %s on line %d
  60. [010] Cannot connect to the server using %s
  61. done!