From 4f4f62fa9a61f1bba789f7f20fd1e479ef0cd12c Mon Sep 17 00:00:00 2001 From: SakiTakamachi Date: Fri, 7 Jul 2023 21:32:43 +0900 Subject: [PATCH 1/7] Fixed the condition that the MYSQLND_OPT_INT_AND_FLOAT_NATIVE becomes true. --- ext/pdo/pdo_dbh.c | 3 +++ ext/pdo_mysql/mysql_driver.c | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 4c8af0597a28c..9544a7215bbf7 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -792,6 +792,9 @@ static bool pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) / return false; } dbh->stringify = bval; + if (dbh->methods->set_attribute) { + dbh->methods->set_attribute(dbh, attr, value); + } return true; case PDO_ATTR_STATEMENT_CLASS: { diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index adccb5e3d0f00..0b88992163c0b 100644 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -459,7 +459,19 @@ static bool pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) ((pdo_mysql_db_handle *)dbh->driver_data)->fetch_table_names = bval; PDO_DBG_RETURN(true); -#ifndef PDO_USE_MYSQLND +#ifdef PDO_USE_MYSQLND + case PDO_ATTR_STRINGIFY_FETCHES: + if (!pdo_get_bool_param(&bval, val)) { + return false; + } + unsigned int int_and_float_native = !bval; + pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; + if (mysql_options(H->server, MYSQLND_OPT_INT_AND_FLOAT_NATIVE, (const char *) &int_and_float_native)) { + pdo_mysql_error(dbh); + return false; + } + PDO_DBG_RETURN(true); +#else case PDO_MYSQL_ATTR_MAX_BUFFER_SIZE: if (!pdo_get_long_param(&lval, val)) { PDO_DBG_RETURN(false); @@ -891,7 +903,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) } #ifdef PDO_USE_MYSQLND - unsigned int int_and_float_native = 1; + !pdo_attr_lval(driver_options, PDO_ATTR_STRINGIFY_FETCHES, dbh->stringify); if (mysql_options(H->server, MYSQLND_OPT_INT_AND_FLOAT_NATIVE, (const char *) &int_and_float_native)) { pdo_mysql_error(dbh); goto cleanup; From 970fc9f3084d2864132b615210deb769163c1812 Mon Sep 17 00:00:00 2001 From: SakiTakamachi Date: Sat, 8 Jul 2023 01:03:14 +0900 Subject: [PATCH 2/7] Restored accidentally deleted parts. --- ext/pdo_mysql/mysql_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index 0b88992163c0b..b4cb6c31df1f6 100644 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -903,7 +903,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) } #ifdef PDO_USE_MYSQLND - !pdo_attr_lval(driver_options, PDO_ATTR_STRINGIFY_FETCHES, dbh->stringify); + unsigned int int_and_float_native = !pdo_attr_lval(driver_options, PDO_ATTR_STRINGIFY_FETCHES, dbh->stringify); if (mysql_options(H->server, MYSQLND_OPT_INT_AND_FLOAT_NATIVE, (const char *) &int_and_float_native)) { pdo_mysql_error(dbh); goto cleanup; From 2f637d911568adee9c05f75b8cdd3be9d001eb3c Mon Sep 17 00:00:00 2001 From: SakiTakamachi Date: Sat, 8 Jul 2023 02:01:35 +0900 Subject: [PATCH 3/7] add test gh-11587.phpt --- ext/pdo_mysql/tests/gh-11587.phpt | 149 ++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 ext/pdo_mysql/tests/gh-11587.phpt diff --git a/ext/pdo_mysql/tests/gh-11587.phpt b/ext/pdo_mysql/tests/gh-11587.phpt new file mode 100644 index 0000000000000..524d8c8002a0b --- /dev/null +++ b/ext/pdo_mysql/tests/gh-11587.phpt @@ -0,0 +1,149 @@ +--TEST-- +GH-11587 PHP8.1: Fixed the condition for result set values to be of native type, making it compatible with previous versions. #11622 +--EXTENSIONS-- +pdo_mysql +--SKIPIF-- + +--FILE-- +exec('DROP TABLE IF EXISTS test'); + +$createTestTable = <<exec($createTestTable); + +$insertTestTable = <<exec($insertTestTable); + +// PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = true +$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); +$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); +$results = $db->query('SELECT * FROM test'); +foreach ($results as $result) { + var_dump($result); +} + +// PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = false +$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); +$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); +$results = $db->query('SELECT * FROM test'); +foreach ($results as $result) { + var_dump($result); +} + +// PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = true +$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false; +$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); +$results = $db->query('SELECT * FROM test'); +foreach ($results as $result) { + var_dump($result); +} + +// PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = false +$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); +$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); +$results = $db->query('SELECT * FROM test'); +foreach ($results as $result) { + var_dump($result); +} + +echo 'done!'; +?> +--CLEAN-- + +--EXPECT-- +array(8) { + ["id"]=> + string(1) "1" + [0]=> + string(1) "1" + ["float_col"]=> + string(4) "2.60" + [1]=> + string(4) "2.60" + ["double_col"]=> + string(4) "3.60" + [2]=> + string(4) "3.60" + ["decimal_col"]=> + string(4) "4.60" + [3]=> + string(4) "4.60" +} +array(8) { + ["id"]=> + int(1) + [0]=> + int(1) + ["float_col"]=> + float(2.6) + [1]=> + float(2.6) + ["double_col"]=> + float(3.6) + [2]=> + float(3.6) + ["decimal_col"]=> + string(4) "4.60" + [3]=> + string(4) "4.60" +} +array(8) { + ["id"]=> + string(1) "1" + [0]=> + string(1) "1" + ["float_col"]=> + string(3) "2.6" + [1]=> + string(3) "2.6" + ["double_col"]=> + string(3) "3.6" + [2]=> + string(3) "3.6" + ["decimal_col"]=> + string(4) "4.60" + [3]=> + string(4) "4.60" +} +array(8) { + ["id"]=> + int(1) + [0]=> + int(1) + ["float_col"]=> + float(2.6) + [1]=> + float(2.6) + ["double_col"]=> + float(3.6) + [2]=> + float(3.6) + ["decimal_col"]=> + string(4) "4.60" + [3]=> + string(4) "4.60" +} +done! From 3b3736dda27f430f39e228fdc5f593baf0a6da75 Mon Sep 17 00:00:00 2001 From: SakiTakamachi Date: Sat, 8 Jul 2023 02:37:46 +0900 Subject: [PATCH 4/7] fix syntax error --- ext/pdo_mysql/tests/gh-11587.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/pdo_mysql/tests/gh-11587.phpt b/ext/pdo_mysql/tests/gh-11587.phpt index 524d8c8002a0b..23d5f40f3225c 100644 --- a/ext/pdo_mysql/tests/gh-11587.phpt +++ b/ext/pdo_mysql/tests/gh-11587.phpt @@ -51,7 +51,7 @@ foreach ($results as $result) { } // PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = true -$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false; +$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); $results = $db->query('SELECT * FROM test'); foreach ($results as $result) { From cd61def3ca4ee9399fc50cc0a8e58812f31885f1 Mon Sep 17 00:00:00 2001 From: SakiTakamachi Date: Fri, 14 Jul 2023 17:02:11 +0900 Subject: [PATCH 5/7] fix "return false" to "PDO_DBG_RETURN" --- ext/pdo_mysql/mysql_driver.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index b4cb6c31df1f6..2d098bffa8724 100644 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -417,7 +417,7 @@ static bool pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) switch (attr) { case PDO_ATTR_AUTOCOMMIT: if (!pdo_get_bool_param(&bval, val)) { - return false; + PDO_DBG_RETURN(false); } /* ignore if the new value equals the old one */ if (dbh->auto_commit ^ bval) { @@ -437,7 +437,7 @@ static bool pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY: if (!pdo_get_bool_param(&bval, val)) { - return false; + PDO_DBG_RETURN(false); } /* ignore if the new value equals the old one */ ((pdo_mysql_db_handle *)dbh->driver_data)->buffered = bval; @@ -446,7 +446,7 @@ static bool pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) case PDO_MYSQL_ATTR_DIRECT_QUERY: case PDO_ATTR_EMULATE_PREPARES: if (!pdo_get_bool_param(&bval, val)) { - return false; + PDO_DBG_RETURN(false); } /* ignore if the new value equals the old one */ ((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = bval; @@ -454,7 +454,7 @@ static bool pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) case PDO_ATTR_FETCH_TABLE_NAMES: if (!pdo_get_bool_param(&bval, val)) { - return false; + PDO_DBG_RETURN(false); } ((pdo_mysql_db_handle *)dbh->driver_data)->fetch_table_names = bval; PDO_DBG_RETURN(true); @@ -462,13 +462,13 @@ static bool pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) #ifdef PDO_USE_MYSQLND case PDO_ATTR_STRINGIFY_FETCHES: if (!pdo_get_bool_param(&bval, val)) { - return false; + PDO_DBG_RETURN(false); } unsigned int int_and_float_native = !bval; pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; if (mysql_options(H->server, MYSQLND_OPT_INT_AND_FLOAT_NATIVE, (const char *) &int_and_float_native)) { pdo_mysql_error(dbh); - return false; + PDO_DBG_RETURN(false); } PDO_DBG_RETURN(true); #else From 4bd7203b05f1f6c96934800dcc4381c38c92facd Mon Sep 17 00:00:00 2001 From: SakiTakamachi Date: Fri, 14 Jul 2023 17:14:19 +0900 Subject: [PATCH 6/7] fix expected and skipif --- ext/pdo_mysql/tests/gh-11587.phpt | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/ext/pdo_mysql/tests/gh-11587.phpt b/ext/pdo_mysql/tests/gh-11587.phpt index 23d5f40f3225c..aa404df649608 100644 --- a/ext/pdo_mysql/tests/gh-11587.phpt +++ b/ext/pdo_mysql/tests/gh-11587.phpt @@ -4,10 +4,10 @@ GH-11587 PHP8.1: Fixed the condition for result set values to be of native type, pdo_mysql --SKIPIF-- --FILE-- @@ -34,7 +34,7 @@ SQL; $db->exec($insertTestTable); -// PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = true +echo "PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = true\n"; $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); $results = $db->query('SELECT * FROM test'); @@ -42,7 +42,9 @@ foreach ($results as $result) { var_dump($result); } -// PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = false +echo "\n"; + +echo "PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = false\n"; $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); $results = $db->query('SELECT * FROM test'); @@ -50,7 +52,9 @@ foreach ($results as $result) { var_dump($result); } -// PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = true +echo "\n"; + +echo "PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = true\n"; $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); $results = $db->query('SELECT * FROM test'); @@ -58,7 +62,9 @@ foreach ($results as $result) { var_dump($result); } -// PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = false +echo "\n"; + +echo "PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = false\n"; $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); $results = $db->query('SELECT * FROM test'); @@ -66,6 +72,8 @@ foreach ($results as $result) { var_dump($result); } +echo "\n"; + echo 'done!'; ?> --CLEAN-- @@ -74,6 +82,7 @@ require __DIR__ . '/mysql_pdo_test.inc'; MySQLPDOTest::dropTestTable(); ?> --EXPECT-- +PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = true array(8) { ["id"]=> string(1) "1" @@ -92,6 +101,8 @@ array(8) { [3]=> string(4) "4.60" } + +PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = false array(8) { ["id"]=> int(1) @@ -110,6 +121,8 @@ array(8) { [3]=> string(4) "4.60" } + +PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = true array(8) { ["id"]=> string(1) "1" @@ -128,6 +141,8 @@ array(8) { [3]=> string(4) "4.60" } + +PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = false array(8) { ["id"]=> int(1) @@ -146,4 +161,5 @@ array(8) { [3]=> string(4) "4.60" } + done! From a16121ca0c7ce96bca17e692b7d687cb247ab9cc Mon Sep 17 00:00:00 2001 From: SakiTakamachi Date: Sat, 15 Jul 2023 14:02:28 +0900 Subject: [PATCH 7/7] fix skipif --- ext/pdo_mysql/tests/gh-11587.phpt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ext/pdo_mysql/tests/gh-11587.phpt b/ext/pdo_mysql/tests/gh-11587.phpt index aa404df649608..45aecba794ab3 100644 --- a/ext/pdo_mysql/tests/gh-11587.phpt +++ b/ext/pdo_mysql/tests/gh-11587.phpt @@ -6,9 +6,7 @@ pdo_mysql --FILE--