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