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