summaryrefslogtreecommitdiffstats
path: root/lib/mysql.php
diff options
context:
space:
mode:
authorDavey Shafik <davey@php.net>2020-10-27 13:34:34 +0000
committerGitHub <noreply@github.com>2020-10-27 13:34:34 +0000
commit6f6c52d748534f50288edf63bba1edfe897bcbf4 (patch)
treeb9b1644462bb30f065ed492e38d7a85ad630d09c /lib/mysql.php
parent8498f6410e7608b623ba2a6030726e5391dd7f4b (diff)
downloadphp7-mysql-shim-6f6c52d748534f50288edf63bba1edfe897bcbf4.zip
php7-mysql-shim-6f6c52d748534f50288edf63bba1edfe897bcbf4.tar.gz
php7-mysql-shim-6f6c52d748534f50288edf63bba1edfe897bcbf4.tar.bz2
Add limited offset support to mysql_fetch_field()
`mysqli` seems to reuse the result objects and doesn't support this feature directly, making this feature very brittle. It should be avoided.
Diffstat (limited to 'lib/mysql.php')
-rw-r--r--lib/mysql.php29
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/mysql.php b/lib/mysql.php
index 909fdec..7c79210 100644
--- a/lib/mysql.php
+++ b/lib/mysql.php
@@ -411,16 +411,39 @@ namespace {
return mysqli_fetch_lengths($result);
}
- function mysql_fetch_field($result) /* : object|*/
+ function mysql_fetch_field($result, $field_offset = null) /* : object|*/
{
+ static $fields = array();
+
if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) {
// @codeCoverageIgnoreStart
return false;
// @codeCoverageIgnoreEnd
}
- $res = mysqli_fetch_field($result);
- if ($res === false) {
+
+ $result_hash = spl_object_hash($result);
+ if ($field_offset === null) {
+ $fields[$result_hash][] = true;
+ $res = mysqli_fetch_field($result);
+ } elseif ($field_offset > mysqli_num_fields($result)) {
trigger_error('mysql_fetch_field(): Bad field offset', E_USER_WARNING);
+ return false;
+ } else {
+ $i = 0;
+ if (isset($fields[$result_hash])) {
+ $i = count($fields[$result_hash]);
+ }
+
+ while ($i <= $field_offset) {
+ $res = mysqli_fetch_field($result);
+
+ if ($res === false) {
+ return false;
+ }
+
+ $fields[$result_hash][$i] = true;
+ $i++;
+ }
}
if ($res instanceof \stdClass) {