mysqli_connect_attr.phpt 2.9 KB

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