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 if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 41 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); 42 43 //in case $host is empty, do not test for _server_host field 44 if (isset($host) && trim($host) != '') { 45 if (!$res = mysqli_query($link, "select * from performance_schema.session_connect_attrs where ATTR_NAME='_server_host' and processlist_id = connection_id()")) { 46 printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 47 } else { 48 $tmp = mysqli_fetch_assoc($res); 49 if (!$tmp || !isset($tmp['ATTR_NAME'])) { 50 echo "[003] _server_host missing\n"; 51 } elseif ($tmp['ATTR_VALUE'] !== $host) { 52 printf("[004] _server_host value mismatch\n") ; 53 } 54 mysqli_free_result($res); 55 } 56 } 57 58 if (!$res = mysqli_query($link, "select * from performance_schema.session_connect_attrs where ATTR_NAME='_client_name' and processlist_id = connection_id()")) { 59 printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 60 } else { 61 $tmp = mysqli_fetch_assoc($res); 62 if (!$tmp || !isset($tmp['ATTR_NAME'])) { 63 echo "[006] _client_name missing\n"; 64 } elseif ($tmp['ATTR_VALUE'] !== "mysqlnd") { 65 printf("[007] _client_name value mismatch\n") ; 66 } 67 mysqli_free_result($res); 68 } 69 70 printf("done!"); 71?> 72--EXPECT-- 73done! 74