1--TEST--
2PDO_MYSQL: check the session_connect_attrs table for connection attributes
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once __DIR__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9MySQLPDOTest::skipNotMySQLnd();
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--FILE--
24<?php
25
26require_once __DIR__ . '/inc/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!
59