summaryrefslogtreecommitdiff
path: root/ext/pdo_mysql
diff options
context:
space:
mode:
authorQianqian Bu <qibu@microsoft.com>2019-08-12 04:00:31 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2019-08-20 13:31:58 +0200
commitcdf16c010a11fc1f91c8807556ccc15b374c0922 (patch)
tree1cc70da2d80d4315ce9306fdf9b0489e0ac4d113 /ext/pdo_mysql
parent81f52158b42318f17f67468cccc4a8dc03bba942 (diff)
downloadphp-git-cdf16c010a11fc1f91c8807556ccc15b374c0922.tar.gz
fix the problem for connect_attr, set db condition, and add a new attribute _server_host
Diffstat (limited to 'ext/pdo_mysql')
-rw-r--r--ext/pdo_mysql/tests/pdo_mysql_connect_attr.phpt58
1 files changed, 58 insertions, 0 deletions
diff --git a/ext/pdo_mysql/tests/pdo_mysql_connect_attr.phpt b/ext/pdo_mysql/tests/pdo_mysql_connect_attr.phpt
new file mode 100644
index 0000000000..2e5285a6e7
--- /dev/null
+++ b/ext/pdo_mysql/tests/pdo_mysql_connect_attr.phpt
@@ -0,0 +1,58 @@
+--TEST--
+PDO_MYSQL: check the session_connect_attrs table for connection attributes
+--SKIPIF--
+<?php
+require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
+require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
+MySQLPDOTest::skip();
+if (!MySQLPDOTest::isPDOMySQLnd()) die('skip only for mysqlnd');
+
+$pdo = MySQLPDOTest::factory();
+
+$stmt = $pdo->query("select count(*) from information_schema.tables where table_schema='performance_schema' and table_name='session_connect_attrs'");
+if (!$stmt || !$stmt->fetchColumn()) {
+ die("skip mysql does not support session_connect_attrs table yet");
+}
+
+$stmt = $pdo->query("show variables like 'performance_schema'");
+if (!$stmt || $stmt->fetchColumn(1) !== 'ON') {
+ die("skip performance_schema is OFF");
+}
+
+?>
+--FILE--
+<?php
+
+require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
+$pdo = MySQLPDOTest::factory();
+
+if (preg_match('/host=([^;]+)/', PDO_MYSQL_TEST_DSN, $m)) {
+ $host = $m[1];
+}
+
+//in case $host is empty, do not test for _server_host field
+if (isset($host) && $host !== '') {
+ $stmt = $pdo->query("select * from performance_schema.session_connect_attrs where ATTR_NAME='_server_host' and processlist_id = connection_id()");
+
+ $row = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if (!$row || !isset($row['attr_name'])) {
+ echo "_server_host missing\n";
+ } elseif ($row['attr_value'] !== $host) {
+ printf("_server_host mismatch (expected '%s', got '%s')\n", $host, $row['attr_value']);
+ }
+}
+
+$stmt = $pdo->query("select * from performance_schema.session_connect_attrs where ATTR_NAME='_client_name' and processlist_id = connection_id()");
+
+$row = $stmt->fetch(PDO::FETCH_ASSOC);
+if (!$row || !isset($row['attr_name'])) {
+ echo "_client_name missing\n";
+} elseif ($row['attr_value'] !== 'mysqlnd') {
+ printf("_client_name mismatch (expected 'mysqlnd', got '%s')\n", $row['attr_value']);
+}
+
+printf("done!");
+?>
+--EXPECT--
+done! \ No newline at end of file