1--TEST--
2PDO_MYSQL: check the session_connect_attrs table for connection attributes
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9if (!MySQLPDOTest::isPDOMySQLnd()) die('skip only for mysqlnd');
10
11$pdo = MySQLPDOTest::factory();
12
13$stmt = $pdo->query("select count(*) from information_schema.tables where table_schema='performance_schema' and table_name='session_connect_attrs'");
14if (!$stmt || !$stmt->fetchColumn()) {
15    die("skip mysql does not support session_connect_attrs table yet");
16}
17
18$stmt = $pdo->query("show variables like 'performance_schema'");
19if (!$stmt || $stmt->fetchColumn(1) !== 'ON') {
20    die("skip performance_schema is OFF");
21}
22
23?>
24--FILE--
25<?php
26
27require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
28$pdo = MySQLPDOTest::factory();
29
30if (preg_match('/host=([^;]+)/', PDO_MYSQL_TEST_DSN, $m)) {
31    $host = $m[1];
32}
33
34//in case $host is empty, do not test for _server_host field
35if (isset($host) && $host !== '') {
36    $stmt = $pdo->query("select * from performance_schema.session_connect_attrs where ATTR_NAME='_server_host' and processlist_id = connection_id()");
37
38    $row = $stmt->fetch(PDO::FETCH_ASSOC);
39
40    if (!$row || !isset($row['attr_name'])) {
41        echo "_server_host missing\n";
42    } elseif ($row['attr_value'] !== $host) {
43        printf("_server_host mismatch (expected '%s', got '%s')\n", $host, $row['attr_value']);
44    }
45}
46
47$stmt = $pdo->query("select * from performance_schema.session_connect_attrs where ATTR_NAME='_client_name' and processlist_id = connection_id()");
48
49$row = $stmt->fetch(PDO::FETCH_ASSOC);
50if (!$row || !isset($row['attr_name'])) {
51    echo "_client_name missing\n";
52} elseif ($row['attr_value'] !== 'mysqlnd') {
53    printf("_client_name mismatch (expected 'mysqlnd', got '%s')\n", $row['attr_value']);
54}
55
56printf("done!");
57?>
58--EXPECT--
59done!