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

+3
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

+4
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

-4
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

+1-11
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

+15-4
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

-1
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

+1-2
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

-2
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

-3
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

-1
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

ext/mysqlnd/mysqlnd_result.c

-37
Original file line numberDiff line numberDiff line change
@@ -1050,49 +1050,12 @@ MYSQLND_METHOD(mysqlnd_res, fetch_row_c)(MYSQLND_RES * result)
10501050
/* }}} */
10511051

10521052

1053-
/* {{{ mysqlnd_res::fetch_all */
1054-
static void
1055-
MYSQLND_METHOD(mysqlnd_res, fetch_all)(MYSQLND_RES * result, const unsigned int flags, zval *return_value ZEND_FILE_LINE_DC)
1056-
{
1057-
zval row;
1058-
zend_ulong i = 0;
1059-
MYSQLND_RES_BUFFERED *set = result->stored_data;
1060-
1061-
DBG_ENTER("mysqlnd_res::fetch_all");
1062-
1063-
if ((!result->unbuf && !set)) {
1064-
php_error_docref(NULL, E_WARNING, "fetch_all can be used only with buffered sets");
1065-
if (result->conn) {
1066-
SET_CLIENT_ERROR(result->conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, "fetch_all can be used only with buffered sets");
1067-
}
1068-
RETVAL_NULL();
1069-
DBG_VOID_RETURN;
1070-
}
1071-
1072-
/* 4 is a magic value. The cast is safe, if larger then the array will be later extended - no big deal :) */
1073-
array_init_size(return_value, set? (unsigned int) set->row_count : 4);
1074-
1075-
do {
1076-
mysqlnd_fetch_into(result, flags, &row);
1077-
if (Z_TYPE(row) != IS_ARRAY) {
1078-
zval_ptr_dtor_nogc(&row);
1079-
break;
1080-
}
1081-
add_index_zval(return_value, i++, &row);
1082-
} while (1);
1083-
1084-
DBG_VOID_RETURN;
1085-
}
1086-
/* }}} */
1087-
1088-
10891053
MYSQLND_CLASS_METHODS_START(mysqlnd_res)
10901054
MYSQLND_METHOD(mysqlnd_res, fetch_row),
10911055
MYSQLND_METHOD(mysqlnd_res, use_result),
10921056
MYSQLND_METHOD(mysqlnd_res, store_result),
10931057
MYSQLND_METHOD(mysqlnd_res, fetch_into),
10941058
MYSQLND_METHOD(mysqlnd_res, fetch_row_c),
1095-
MYSQLND_METHOD(mysqlnd_res, fetch_all),
10961059
MYSQLND_METHOD(mysqlnd_res, num_rows),
10971060
MYSQLND_METHOD(mysqlnd_res, num_fields),
10981061
MYSQLND_METHOD(mysqlnd_res, skip_result),

ext/mysqlnd/mysqlnd_structs.h

-2
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,6 @@ typedef MYSQLND_RES * (*func_mysqlnd_res__use_result)(MYSQLND_RES * const resul
640640
typedef MYSQLND_RES * (*func_mysqlnd_res__store_result)(MYSQLND_RES * result, MYSQLND_CONN_DATA * const conn, MYSQLND_STMT_DATA *stmt);
641641
typedef void (*func_mysqlnd_res__fetch_into)(MYSQLND_RES *result, const unsigned int flags, zval *return_value ZEND_FILE_LINE_DC);
642642
typedef MYSQLND_ROW_C (*func_mysqlnd_res__fetch_row_c)(MYSQLND_RES *result);
643-
typedef void (*func_mysqlnd_res__fetch_all)(MYSQLND_RES *result, const unsigned int flags, zval *return_value ZEND_FILE_LINE_DC);
644643
typedef uint64_t (*func_mysqlnd_res__num_rows)(const MYSQLND_RES * const result);
645644
typedef unsigned int (*func_mysqlnd_res__num_fields)(const MYSQLND_RES * const result);
646645
typedef enum_func_status (*func_mysqlnd_res__skip_result)(MYSQLND_RES * const result);
@@ -671,7 +670,6 @@ MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res)
671670
func_mysqlnd_res__store_result store_result;
672671
func_mysqlnd_res__fetch_into fetch_into;
673672
func_mysqlnd_res__fetch_row_c fetch_row_c;
674-
func_mysqlnd_res__fetch_all fetch_all;
675673
func_mysqlnd_res__num_rows num_rows;
676674
func_mysqlnd_res__num_fields num_fields;
677675
func_mysqlnd_res__skip_result skip_result;

0 commit comments

Comments
 (0)