Skip to content

Commit 037512c

Browse files
committed
Move fetch_all implementation out of mysqlnd
There doesn't seem to be any compelling reason to implement this in mysqlnd rather than mysqli. It's just a loop over fetch_into. This makes the function available under libmysqlclient as well, and thus fixes bug #79372.
1 parent be93e5a commit 037512c

12 files changed

+24
-67
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ PHP NEWS
1515
- hash:
1616
. Implemented FR #68109 (Add MurmurHash V3). (Anatol, Michael)
1717

18+
- MySQLi:
19+
. Fixed bug #70372 (Emulate mysqli_fetch_all() for libmysqlclient). (Nikita)
20+
1821
- OpenSSL:
1922
. Bump minimal OpenSSL version to 1.0.2. (Jakub Zelenka)
2023

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ PHP 8.1 UPGRADE NOTES
9696
9. Other Changes to Extensions
9797
========================================
9898

99+
- MySQLi:
100+
. The mysqli_stmt::next_result() and mysqli::fetch_all() methods are now
101+
available when linking against libmysqlclient.
102+
99103
- OpenSSL:
100104
. The OpenSSL extension now requires at least OpenSSL version 1.0.2.
101105

ext/mysqli/mysqli.stub.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,11 @@ public function fetch_fields() {}
340340
*/
341341
public function fetch_field_direct(int $index) {}
342342

343-
#if defined(MYSQLI_USE_MYSQLND)
344343
/**
345344
* @return array|false
346345
* @alias mysqli_fetch_all
347346
*/
348347
public function fetch_all(int $mode = MYSQLI_NUM) {}
349-
#endif
350348

351349
/**
352350
* @return array|null|false
@@ -573,9 +571,7 @@ function mysqli_fetch_field_direct(mysqli_result $result, int $index): object|fa
573571

574572
function mysqli_fetch_lengths(mysqli_result $result): array|false {}
575573

576-
#if defined(MYSQLI_USE_MYSQLND)
577574
function mysqli_fetch_all(mysqli_result $result, int $mode = MYSQLI_NUM): array|false {}
578-
#endif
579575

580576
function mysqli_fetch_array(mysqli_result $result, int $mode = MYSQLI_BOTH): array|null|false {}
581577

ext/mysqli/mysqli_arginfo.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 6af7fe4ad33232a118fdde74d13e0fb8a04fb4b0 */
2+
* Stub hash: 8cd300f5106294e193fa85adc9c8a18a68d7d322 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_affected_rows, 0, 1, MAY_BE_LONG|MAY_BE_STRING)
55
ZEND_ARG_OBJ_INFO(0, mysql, mysqli, 0)
@@ -96,12 +96,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_fetch_lengths, 0, 1, MAY_
9696
ZEND_ARG_OBJ_INFO(0, result, mysqli_result, 0)
9797
ZEND_END_ARG_INFO()
9898

99-
#if defined(MYSQLI_USE_MYSQLND)
10099
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_fetch_all, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
101100
ZEND_ARG_OBJ_INFO(0, result, mysqli_result, 0)
102101
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "MYSQLI_NUM")
103102
ZEND_END_ARG_INFO()
104-
#endif
105103

106104
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_fetch_array, 0, 1, MAY_BE_ARRAY|MAY_BE_NULL|MAY_BE_FALSE)
107105
ZEND_ARG_OBJ_INFO(0, result, mysqli_result, 0)
@@ -598,11 +596,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_result_fetch_field_direct, 0, 0, 1)
598596
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
599597
ZEND_END_ARG_INFO()
600598

601-
#if defined(MYSQLI_USE_MYSQLND)
602599
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_result_fetch_all, 0, 0, 0)
603600
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "MYSQLI_NUM")
604601
ZEND_END_ARG_INFO()
605-
#endif
606602

607603
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_result_fetch_array, 0, 0, 0)
608604
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "MYSQLI_BOTH")
@@ -710,9 +706,7 @@ ZEND_FUNCTION(mysqli_fetch_field);
710706
ZEND_FUNCTION(mysqli_fetch_fields);
711707
ZEND_FUNCTION(mysqli_fetch_field_direct);
712708
ZEND_FUNCTION(mysqli_fetch_lengths);
713-
#if defined(MYSQLI_USE_MYSQLND)
714709
ZEND_FUNCTION(mysqli_fetch_all);
715-
#endif
716710
ZEND_FUNCTION(mysqli_fetch_array);
717711
ZEND_FUNCTION(mysqli_fetch_assoc);
718712
ZEND_FUNCTION(mysqli_fetch_object);
@@ -836,9 +830,7 @@ static const zend_function_entry ext_functions[] = {
836830
ZEND_FE(mysqli_fetch_fields, arginfo_mysqli_fetch_fields)
837831
ZEND_FE(mysqli_fetch_field_direct, arginfo_mysqli_fetch_field_direct)
838832
ZEND_FE(mysqli_fetch_lengths, arginfo_mysqli_fetch_lengths)
839-
#if defined(MYSQLI_USE_MYSQLND)
840833
ZEND_FE(mysqli_fetch_all, arginfo_mysqli_fetch_all)
841-
#endif
842834
ZEND_FE(mysqli_fetch_array, arginfo_mysqli_fetch_array)
843835
ZEND_FE(mysqli_fetch_assoc, arginfo_mysqli_fetch_assoc)
844836
ZEND_FE(mysqli_fetch_object, arginfo_mysqli_fetch_object)
@@ -1003,9 +995,7 @@ static const zend_function_entry class_mysqli_result_methods[] = {
1003995
ZEND_ME_MAPPING(fetch_field, mysqli_fetch_field, arginfo_class_mysqli_result_fetch_field, ZEND_ACC_PUBLIC)
1004996
ZEND_ME_MAPPING(fetch_fields, mysqli_fetch_fields, arginfo_class_mysqli_result_fetch_fields, ZEND_ACC_PUBLIC)
1005997
ZEND_ME_MAPPING(fetch_field_direct, mysqli_fetch_field_direct, arginfo_class_mysqli_result_fetch_field_direct, ZEND_ACC_PUBLIC)
1006-
#if defined(MYSQLI_USE_MYSQLND)
1007998
ZEND_ME_MAPPING(fetch_all, mysqli_fetch_all, arginfo_class_mysqli_result_fetch_all, ZEND_ACC_PUBLIC)
1008-
#endif
1009999
ZEND_ME_MAPPING(fetch_array, mysqli_fetch_array, arginfo_class_mysqli_result_fetch_array, ZEND_ACC_PUBLIC)
10101000
ZEND_ME_MAPPING(fetch_assoc, mysqli_fetch_assoc, arginfo_class_mysqli_result_fetch_assoc, ZEND_ACC_PUBLIC)
10111001
ZEND_ME_MAPPING(fetch_object, mysqli_fetch_object, arginfo_class_mysqli_result_fetch_object, ZEND_ACC_PUBLIC)

ext/mysqli/mysqli_nonapi.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,28 +431,39 @@ PHP_FUNCTION(mysqli_fetch_assoc)
431431
/* }}} */
432432

433433
/* {{{ Fetches all result rows as an associative array, a numeric array, or both */
434-
#ifdef MYSQLI_USE_MYSQLND
435434
PHP_FUNCTION(mysqli_fetch_all)
436435
{
437436
MYSQL_RES *result;
438437
zval *mysql_result;
439-
zend_long mode = MYSQLND_FETCH_NUM;
438+
zend_long mode = MYSQLI_NUM;
440439

441440
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &mode) == FAILURE) {
442441
RETURN_THROWS();
443442
}
444443
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
445444

446-
if (!mode || (mode & ~MYSQLND_FETCH_BOTH)) {
445+
if (!mode || (mode & ~MYSQLI_BOTH)) {
447446
zend_argument_value_error(ERROR_ARG_POS(2), "must be one of MYSQLI_FETCH_NUM, "
448447
"MYSQLI_FETCH_ASSOC, or MYSQLI_FETCH_BOTH");
449448
RETURN_THROWS();
450449
}
451450

452-
mysqlnd_fetch_all(result, mode, return_value);
451+
array_init_size(return_value, mysql_num_rows(result));
452+
453+
zend_ulong i = 0;
454+
do {
455+
zval row;
456+
php_mysqli_fetch_into_hash_aux(&row, result, mode);
457+
if (Z_TYPE(row) != IS_ARRAY) {
458+
zval_ptr_dtor_nogc(&row);
459+
break;
460+
}
461+
add_index_zval(return_value, i++, &row);
462+
} while (1);
453463
}
454464
/* }}} */
455465

466+
#ifdef MYSQLI_USE_MYSQLND
456467
/* {{{ Returns statistics about the zval cache */
457468
PHP_FUNCTION(mysqli_get_client_stats)
458469
{

ext/mysqli/tests/bug75434.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Bug #75434 Wrong reflection for mysqli_fetch_all function
33
--SKIPIF--
44
<?php
55
require_once('skipif.inc');
6-
if (!stristr(mysqli_get_client_info(), 'mysqlnd')) die("skip: only available in mysqlnd");
76
?>
87
--FILE--
98
<?php

ext/mysqli/tests/mysqli_class_mysqli_result_interface.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require_once('skipifconnectfailure.inc');
2727
'__construct' => true,
2828
'close' => true,
2929
'data_seek' => true,
30+
'fetch_all' => true,
3031
'fetch_array' => true,
3132
'fetch_assoc' => true,
3233
'fetch_field' => true,
@@ -39,8 +40,6 @@ require_once('skipifconnectfailure.inc');
3940
'free_result' => true,
4041
'getIterator' => true,
4142
);
42-
if ($IS_MYSQLND)
43-
$expected_methods['fetch_all'] = true;
4443

4544
foreach ($methods as $k => $method) {
4645
if (isset($expected_methods[$method])) {

ext/mysqli/tests/mysqli_fetch_all.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ mysqli_fetch_all()
44
<?php
55
require_once('skipif.inc');
66
require_once('skipifconnectfailure.inc');
7-
if (!function_exists('mysqli_fetch_all'))
8-
die("skip: function only available with mysqlnd");
97
?>
108
--FILE--
119
<?php

ext/mysqli/tests/mysqli_fetch_all_oo.phpt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ $mysqli->fetch_all() (introduced with mysqlnd)
44
<?php
55
require_once('skipif.inc');
66
require_once('skipifconnectfailure.inc');
7-
8-
if (!function_exists('mysqli_fetch_all'))
9-
die("skip: function only available with mysqlnd");
107
?>
118
--FILE--
129
<?php

ext/mysqlnd/mysqlnd.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ PHPAPI void mysqlnd_debug(const char *mode);
102102
#define mysqlnd_fetch_row_c(result) (result)->m.fetch_row_c((result))
103103
#define mysqlnd_fetch_row_zval(result, row_ptr, fetched) \
104104
(result)->m.fetch_row((result), (row_ptr), 0, (fetched))
105-
#define mysqlnd_fetch_all(result, flags, return_value) (result)->m.fetch_all((result), (flags), (return_value) ZEND_FILE_LINE_CC)
106105
#define mysqlnd_get_connection_stats(conn, values) ((conn)->data)->m->get_statistics((conn)->data, (values) ZEND_FILE_LINE_CC)
107106
#define mysqlnd_get_client_stats(values) _mysqlnd_get_client_stats(mysqlnd_global_stats, (values) ZEND_FILE_LINE_CC)
108107

0 commit comments

Comments
 (0)