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