From 4023f2488bfd7bbf50ded2f106c25b318df5b15c Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 20 Jan 2025 12:04:17 -0400 Subject: [PATCH 1/4] ext/mysqli: Skip test that needs superuser This test needs CREATE DATABASE and CREATE SERVER, and will fail in the cleanup step if it doesn't have it. If the test is running as a user that can't do these, then we should skip instead of borking. Alternative to GH-17466. --- ext/mysqli/tests/mysqli_get_client_stats.phpt | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/ext/mysqli/tests/mysqli_get_client_stats.phpt b/ext/mysqli/tests/mysqli_get_client_stats.phpt index 17900c5ad6090..bb67397238d21 100644 --- a/ext/mysqli/tests/mysqli_get_client_stats.phpt +++ b/ext/mysqli/tests/mysqli_get_client_stats.phpt @@ -4,7 +4,33 @@ mysqli_get_client_stats() mysqli --SKIPIF-- close(); + mysqli_query($link, "DROP DATABASE mysqli_get_client_stats"); + } catch (\mysqli_sql_exception) { + die("skip don't have create database privilege"); + } + try { + $sql = sprintf("CREATE SERVER myself FOREIGN DATA WRAPPER mysql OPTIONS (user '%s', password '%s', database '%s')", + get_default_user(), get_default_password(), get_default_database()); + $stmt = mysqli_query($link, $sql); + $stmt->close(); + mysqli_query($link, "DROP SERVER myself"); + } catch(\mysqli_sql_exception) { + die("skip don't have create server privilege"); + } + mysqli_close($link); ?> --INI-- mysqlnd.collect_statistics=1 From 7814454a3f70af52b8f0def12b7697130b38cd0c Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 20 Jan 2025 12:35:10 -0400 Subject: [PATCH 2/4] simplify create database skipif Co-authored-by: Kamil Tekiela --- ext/mysqli/tests/mysqli_get_client_stats.phpt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/mysqli/tests/mysqli_get_client_stats.phpt b/ext/mysqli/tests/mysqli_get_client_stats.phpt index bb67397238d21..6a0460e192306 100644 --- a/ext/mysqli/tests/mysqli_get_client_stats.phpt +++ b/ext/mysqli/tests/mysqli_get_client_stats.phpt @@ -15,9 +15,8 @@ mysqli // we need to execute and clean up. try { $sql = "CREATE DATABASE mysqli_get_client_stats"; - $stmt = mysqli_query($link, $sql); - $stmt->close(); - mysqli_query($link, "DROP DATABASE mysqli_get_client_stats"); + mysqli_query($link, $sql); + mysqli_query($link, "DROP DATABASE mysqli_get_client_stats"); } catch (\mysqli_sql_exception) { die("skip don't have create database privilege"); } From 4479c7544f1c9094b7654076a515b1668e47d4a6 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 20 Jan 2025 12:35:45 -0400 Subject: [PATCH 3/4] simplify create server skipif Co-authored-by: Kamil Tekiela --- ext/mysqli/tests/mysqli_get_client_stats.phpt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/mysqli/tests/mysqli_get_client_stats.phpt b/ext/mysqli/tests/mysqli_get_client_stats.phpt index 6a0460e192306..393740c8233d1 100644 --- a/ext/mysqli/tests/mysqli_get_client_stats.phpt +++ b/ext/mysqli/tests/mysqli_get_client_stats.phpt @@ -23,8 +23,7 @@ mysqli try { $sql = sprintf("CREATE SERVER myself FOREIGN DATA WRAPPER mysql OPTIONS (user '%s', password '%s', database '%s')", get_default_user(), get_default_password(), get_default_database()); - $stmt = mysqli_query($link, $sql); - $stmt->close(); + mysqli_query($link, $sql); mysqli_query($link, "DROP SERVER myself"); } catch(\mysqli_sql_exception) { die("skip don't have create server privilege"); From dc2a3ad3a284505dd183a26c19428a2ea64a2c23 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 20 Jan 2025 13:08:49 -0400 Subject: [PATCH 4/4] don't explain why we don't prepare instead --- ext/mysqli/tests/mysqli_get_client_stats.phpt | 3 --- 1 file changed, 3 deletions(-) diff --git a/ext/mysqli/tests/mysqli_get_client_stats.phpt b/ext/mysqli/tests/mysqli_get_client_stats.phpt index 393740c8233d1..da36e5de57f69 100644 --- a/ext/mysqli/tests/mysqli_get_client_stats.phpt +++ b/ext/mysqli/tests/mysqli_get_client_stats.phpt @@ -10,9 +10,6 @@ mysqli // this test, so check if we can do that. We don't check if we can merely // create a table; if that doesn't work with the provided database, many // more tests would fail. - - // It seems DML can be privilege checked on prepare, but DML can't be, so - // we need to execute and clean up. try { $sql = "CREATE DATABASE mysqli_get_client_stats"; mysqli_query($link, $sql);