mysqli_connect_attr.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. --TEST--
  2. mysqli check the session_connect_attrs table for connection attributes
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. if (!$IS_MYSQLND)
  8. die("skip: test applies only to mysqlnd");
  9. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  10. die("skip Cannot connect to the server");
  11. /* skip test if the server version does not have session_connect_attrs table yet*/
  12. if (!$res = mysqli_query($link, "select count(*) as count from information_schema.tables where table_schema='performance_schema' and table_name='session_connect_attrs';"))
  13. die("skip select from information_schema.tables for session_connect_attrs query failed");
  14. $tmp = mysqli_fetch_assoc($res);
  15. mysqli_free_result($res);
  16. if($tmp['count'] == "0") {
  17. mysqli_close($link);
  18. die("skip mysql does not support session_connect_attrs table yet");
  19. }
  20. /* skip test if performance_schema is OFF*/
  21. if (!$res = mysqli_query($link, "show variables like 'performance_schema';"))
  22. die("skip show variables like 'performance_schema' failed");
  23. $tmp = mysqli_fetch_assoc($res);
  24. mysqli_free_result($res);
  25. if($tmp['Value'] == "OFF") {
  26. mysqli_close($link);
  27. die("skip performance_schema is OFF");
  28. }
  29. mysqli_close($link);
  30. ?>
  31. --FILE--
  32. <?php
  33. require_once("connect.inc");
  34. $tmp = NULL;
  35. $link = NULL;
  36. $res = NULL;
  37. if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  38. printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",$host, $user, $db, $port, $socket);
  39. //in case $host is empty, do not test for _server_host field
  40. if (isset($host) && trim($host) != '') {
  41. if (!$res = mysqli_query($link, "select * from performance_schema.session_connect_attrs where ATTR_NAME='_server_host' and processlist_id = connection_id()")) {
  42. printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  43. } else {
  44. $tmp = mysqli_fetch_assoc($res);
  45. if (!$tmp || !isset($tmp['ATTR_NAME'])) {
  46. echo "[003] _server_host missing\n";
  47. } elseif ($tmp['ATTR_VALUE'] !== $host) {
  48. printf("[004] _server_host value mismatch\n") ;
  49. }
  50. mysqli_free_result($res);
  51. }
  52. }
  53. if (!$res = mysqli_query($link, "select * from performance_schema.session_connect_attrs where ATTR_NAME='_client_name' and processlist_id = connection_id()")) {
  54. printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  55. } else {
  56. $tmp = mysqli_fetch_assoc($res);
  57. if (!$tmp || !isset($tmp['ATTR_NAME'])) {
  58. echo "[006] _client_name missing\n";
  59. } elseif ($tmp['ATTR_VALUE'] !== "mysqlnd") {
  60. printf("[007] _client_name value mismatch\n") ;
  61. }
  62. mysqli_free_result($res);
  63. }
  64. printf("done!");
  65. ?>
  66. --EXPECTF--
  67. done!