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