mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
ext/mysqli: Deprecate passing the parameter to mysqli_store_result() (#15311)
And deprecate the MYSQLI_STORE_RESULT_COPY_DATA constant. RFC: https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_the_second_parameter_to_mysqli_store_result
This commit is contained in:
committed by
GitHub
parent
857ce2c9e0
commit
4f58d5b0df
3
NEWS
3
NEWS
@@ -41,6 +41,9 @@ PHP NEWS
|
||||
. The mysqli_refresh() function and mysqli::refresh() method are now deprecated.
|
||||
If this functionality is needed a SQL "FLUSH" command can be used instead.
|
||||
(Kamil Tekiela)
|
||||
. Passing explicitly the $mode parameter to mysqli_store_result() has been
|
||||
deprecated. As the MYSQLI_STORE_RESULT_COPY_DATA constant was only used in
|
||||
conjunction with this function it has also been deprecated. (Girgias)
|
||||
|
||||
- PHPDBG:
|
||||
. array out of bounds, stack overflow handled for segfault handler on windows.
|
||||
|
||||
@@ -457,6 +457,10 @@ PHP 8.4 UPGRADE NOTES
|
||||
. The mysqli_refresh() function and mysqli::refresh() method are now deprecated.
|
||||
If this functionality is needed a SQL "FLUSH" command can be used instead.
|
||||
RFC: https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_mysqli_refresh
|
||||
. Passing explicitly the $mode parameter to mysqli_store_result() has been
|
||||
deprecated. As the MYSQLI_STORE_RESULT_COPY_DATA constant was only used in
|
||||
conjunction with this function it has also been deprecated.
|
||||
RFC: https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_the_second_parameter_to_mysqli_store_result
|
||||
|
||||
- PDO_PGSQL:
|
||||
. Using escaped question marks (??) inside dollar-quoted strings is deprecated.
|
||||
|
||||
@@ -138,6 +138,7 @@ const MYSQLI_ASYNC = UNKNOWN;
|
||||
/**
|
||||
* @var int
|
||||
* @cvalue MYSQLI_STORE_RESULT_COPY_DATA
|
||||
* @deprecated
|
||||
*/
|
||||
const MYSQLI_STORE_RESULT_COPY_DATA = UNKNOWN;
|
||||
|
||||
|
||||
@@ -1957,6 +1957,14 @@ PHP_FUNCTION(mysqli_store_result)
|
||||
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &mysql_link, mysqli_link_class_entry, &flags) == FAILURE) {
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
if ((hasThis() && ZEND_NUM_ARGS() == 1) || ZEND_NUM_ARGS() == 2) {
|
||||
zend_error(E_DEPRECATED, "Passing the $mode parameter is deprecated since 8.4, as it has been ignored since 8.1");
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
RETURN_THROWS();
|
||||
}
|
||||
}
|
||||
|
||||
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
|
||||
result = mysql_store_result(mysql->mysql);
|
||||
if (!result) {
|
||||
|
||||
@@ -18,7 +18,7 @@ $mysqli->query('INSERT INTO test VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9)');
|
||||
|
||||
$mysqli->real_query("SELECT * FROM test");
|
||||
|
||||
$result = $mysqli->store_result(MYSQLI_STORE_RESULT_COPY_DATA);
|
||||
$result = $mysqli->store_result();
|
||||
|
||||
$field = $result->fetch_field();
|
||||
var_dump($field->name);
|
||||
|
||||
@@ -13,7 +13,7 @@ require_once 'skipifconnectfailure.inc';
|
||||
if (!$res = mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id"))
|
||||
printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
if (!is_object($res = mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA)))
|
||||
if (!is_object($res = mysqli_store_result($link)))
|
||||
printf("[004] Expecting object, got %s/%s. [%d] %s\n",
|
||||
gettype($res), $res, mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
|
||||
@@ -1,281 +0,0 @@
|
||||
--TEST--
|
||||
mysqli_store_result()
|
||||
--EXTENSIONS--
|
||||
mysqli
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once 'skipifconnectfailure.inc';
|
||||
?>
|
||||
--INI--
|
||||
mysqlnd.debug="d:t:O,{TMP}/mysqlnd.trace"
|
||||
mysqlnd.net_read_buffer_size=1
|
||||
mysqlnd.mempool_default_size=1
|
||||
mysqlnd.fetch_data_copy=0
|
||||
--FILE--
|
||||
<?php
|
||||
require 'table.inc';
|
||||
|
||||
if (!$res = mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id"))
|
||||
printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
if (!is_object($res = mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA)))
|
||||
printf("[004] Expecting object, got %s/%s. [%d] %s\n",
|
||||
gettype($res), $res, mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
if (true !== ($tmp = mysqli_data_seek($res, 2)))
|
||||
printf("[005] Expecting boolean/true, got %s/%s. [%d] %s\n",
|
||||
gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
var_dump($res->fetch_assoc());
|
||||
|
||||
if (true !== ($tmp = mysqli_data_seek($res, 0)))
|
||||
printf("[006] Expecting boolean/true, got %s/%s. [%d] %s\n",
|
||||
gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
while ($row = $res->fetch_assoc()) {
|
||||
printf("id = %d, label = %s\n", $row['id'], $row['label']);
|
||||
}
|
||||
|
||||
mysqli_free_result($res);
|
||||
mysqli_close($link);
|
||||
|
||||
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
|
||||
printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
|
||||
$host, $user, $db, $port, $socket);
|
||||
}
|
||||
|
||||
|
||||
if (!$res = mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id"))
|
||||
printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
if (!is_object($res = mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA)))
|
||||
printf("[009] Expecting object, got %s/%s. [%d] %s\n",
|
||||
gettype($res), $res, mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
$no_result = 0;
|
||||
for ($i = 0; $i < 1000; $i++) {
|
||||
$idx = mt_rand(-100, 100);
|
||||
try {
|
||||
if (true === @mysqli_data_seek($res, $idx)) {
|
||||
$row = $res->fetch_assoc();
|
||||
if (!isset($row['id']) || !isset($row['label'])) {
|
||||
printf("[010] Brute force seek %d returned %d\n", $idx, var_export($row, true));
|
||||
}
|
||||
} else {
|
||||
$no_result++;
|
||||
}
|
||||
} catch (\ValueError $e) {
|
||||
$no_result++;
|
||||
}
|
||||
}
|
||||
printf("No result: %d\n", $no_result);
|
||||
|
||||
/* implicit free, implicit store */
|
||||
/* meta and fetch lengths code */
|
||||
if (!$res = mysqli_query($link, "SELECT CONCAT(id, id) AS _c, label FROM test ORDER BY id DESC LIMIT 2"))
|
||||
printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
printf("Default\n");
|
||||
var_dump(mysqli_fetch_lengths($res));
|
||||
$fields = $res->fetch_fields();
|
||||
while ($row = $res->fetch_assoc()) {
|
||||
var_dump(mysqli_fetch_lengths($res));
|
||||
}
|
||||
var_dump(mysqli_fetch_lengths($res));
|
||||
|
||||
if (!$res = mysqli_real_query($link, "SELECT CONCAT(id, id) AS _c, label FROM test ORDER BY id DESC LIMIT 2"))
|
||||
printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
if (!is_object($res = mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA)))
|
||||
printf("[013] Expecting object, got %s/%s. [%d] %s\n",
|
||||
gettype($res), $res, mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
printf("Copy\n");
|
||||
var_dump(mysqli_fetch_lengths($res));
|
||||
$fields_copy = $res->fetch_fields();
|
||||
while ($row = $res->fetch_assoc()) {
|
||||
var_dump(mysqli_fetch_lengths($res));
|
||||
}
|
||||
var_dump(mysqli_fetch_lengths($res));
|
||||
|
||||
/* There's no need for in-depth testing here. If you want in-depth switch mysqlnd
|
||||
globally to copy mode and run all the tests */
|
||||
foreach ($fields as $k => $field_info) {
|
||||
if ($fields_copy[$k] != $field_info) {
|
||||
printf("[014] Metadata seems to differ, dumping\n");
|
||||
var_dump($field_info);
|
||||
var_dump($fields_copy[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
/* fetch all */
|
||||
|
||||
if (!$res = mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id DESC LIMIT 2"))
|
||||
printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
if (!is_object($res = mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA)))
|
||||
printf("[016] Expecting object, got %s/%s. [%d] %s\n",
|
||||
gettype($res), $res, mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
foreach (mysqli_fetch_all($res, MYSQLI_ASSOC) as $row) {
|
||||
printf("id = %d label = %s\n", $row['id'], $row['label']);
|
||||
}
|
||||
|
||||
if (!$res = mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id DESC LIMIT 2"))
|
||||
printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
if (!is_object($res = mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA)))
|
||||
printf("[018] Expecting object, got %s/%s. [%d] %s\n",
|
||||
gettype($res), $res, mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
/* provoke out of sync */
|
||||
if (!mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id DESC LIMIT 2"))
|
||||
printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
var_dump($res->fetch_assoc());
|
||||
|
||||
if (!$res = mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2"))
|
||||
printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
if (!is_object($res = mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA)))
|
||||
printf("[021] Expecting object, got %s/%s. [%d] %s\n",
|
||||
gettype($res), $res, mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
/* user conn killed, res associated with conn, fetch from res */
|
||||
unset($link);
|
||||
var_dump($res->fetch_assoc());
|
||||
|
||||
|
||||
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
|
||||
printf("[022] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
|
||||
$host, $user, $db, $port, $socket);
|
||||
}
|
||||
|
||||
if (!$res = mysqli_real_query($link, "INSERT INTO test(id, label) VALUES (100, 'z')"))
|
||||
printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA);
|
||||
|
||||
if (mysqli_get_server_version($link) > 50000) {
|
||||
// let's try to play with stored procedures
|
||||
mysqli_real_query($link, 'DROP PROCEDURE IF EXISTS p');
|
||||
if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) READS SQL DATA BEGIN SELECT id FROM test WHERE id >= 100 ORDER BY id; SELECT id + 1, label FROM test WHERE id > 0 AND id < 3 ORDER BY id; SELECT VERSION() INTO ver_param;
|
||||
END;')) {
|
||||
mysqli_multi_query($link, "CALL p(@version)");
|
||||
do {
|
||||
if ($res = $link->store_result(MYSQLI_STORE_RESULT_COPY_DATA)) {
|
||||
printf("---\n");
|
||||
var_dump($res->fetch_all());
|
||||
$res->free();
|
||||
} else {
|
||||
if ($link->errno) {
|
||||
echo "Store failed: (" . $link->errno . ") " . $link->error;
|
||||
}
|
||||
}
|
||||
} while ($link->more_results() && $link->next_result());
|
||||
mysqli_real_query($link, 'SELECT @version AS p_version');
|
||||
$res = mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA);
|
||||
|
||||
$tmp = mysqli_fetch_assoc($res);
|
||||
if (!is_array($tmp) || empty($tmp) || !isset($tmp['p_version']) || ('' == $tmp['p_version'])) {
|
||||
printf("[024] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
var_dump($tmp);
|
||||
}
|
||||
|
||||
mysqli_free_result($res);
|
||||
} else {
|
||||
printf("[025] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
}
|
||||
}
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
--CLEAN--
|
||||
<?php
|
||||
require_once 'clean_table.inc';
|
||||
?>
|
||||
--EXPECTF--
|
||||
array(2) {
|
||||
["id"]=>
|
||||
string(1) "3"
|
||||
["label"]=>
|
||||
string(1) "c"
|
||||
}
|
||||
id = 1, label = a
|
||||
id = 2, label = b
|
||||
id = 3, label = c
|
||||
id = 4, label = d
|
||||
id = 5, label = e
|
||||
id = 6, label = f
|
||||
No result: %d
|
||||
Default
|
||||
bool(false)
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(2)
|
||||
[1]=>
|
||||
int(1)
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(2)
|
||||
[1]=>
|
||||
int(1)
|
||||
}
|
||||
bool(false)
|
||||
Copy
|
||||
bool(false)
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(2)
|
||||
[1]=>
|
||||
int(1)
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(2)
|
||||
[1]=>
|
||||
int(1)
|
||||
}
|
||||
bool(false)
|
||||
id = 6 label = f
|
||||
id = 5 label = e
|
||||
array(2) {
|
||||
["id"]=>
|
||||
string(1) "6"
|
||||
["label"]=>
|
||||
string(1) "f"
|
||||
}
|
||||
[020] [2014] %s
|
||||
array(2) {
|
||||
["id"]=>
|
||||
string(1) "6"
|
||||
["label"]=>
|
||||
string(1) "f"
|
||||
}
|
||||
---
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(3) "100"
|
||||
}
|
||||
}
|
||||
---
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(1) "2"
|
||||
[1]=>
|
||||
string(1) "a"
|
||||
}
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(1) "3"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
}
|
||||
}
|
||||
done!
|
||||
Reference in New Issue
Block a user