summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/mysql.php4
-rw-r--r--tests/MySqlShimTest.php11
2 files changed, 9 insertions, 6 deletions
diff --git a/lib/mysql.php b/lib/mysql.php
index 7f6f008..909fdec 100644
--- a/lib/mysql.php
+++ b/lib/mysql.php
@@ -419,6 +419,10 @@ namespace {
// @codeCoverageIgnoreEnd
}
$res = mysqli_fetch_field($result);
+ if ($res === false) {
+ trigger_error('mysql_fetch_field(): Bad field offset', E_USER_WARNING);
+ }
+
if ($res instanceof \stdClass) {
$res->not_null = ($res->flags & MYSQLI_NOT_NULL_FLAG) ? 1 : 0;
$res->primary_key = ($res->flags & MYSQLI_PRI_KEY_FLAG ) ? 1 : 0;
diff --git a/tests/MySqlShimTest.php b/tests/MySqlShimTest.php
index 701cabd..875c5ed 100644
--- a/tests/MySqlShimTest.php
+++ b/tests/MySqlShimTest.php
@@ -1059,8 +1059,8 @@ class MySqlShimTest extends \Yoast\PHPUnitPolyfills\TestCases\TestCase
public function test_mysql_fetch_field_fail_invalid()
{
- // $this->expectWarning();
- // $this->expectWarningMessage("mysql_fetch_field() expects parameter 1 to be resource, boolean given");
+ $this->expectWarning();
+ $this->expectWarningMessage("mysql_fetch_field(): Bad field offset");
$this->getConnection();
@@ -1071,12 +1071,11 @@ class MySqlShimTest extends \Yoast\PHPUnitPolyfills\TestCases\TestCase
('six', '6', '6', '6', '6', '6', '6', '6', 'six', 'six', '6')"
);
- $result = mysql_query("SELECT * FROM testing WHERE one = 'six' LIMIT 1");
+ $result = mysql_query("SELECT one FROM testing WHERE one = 'six' LIMIT 1");
$this->assertNotFalse($result);
- for ($i = 0; $i <= 12; $i++) {
- $field = mysql_fetch_field($result, $i);
- }
+
+ $field = mysql_fetch_field($result, 2);
$this->assertFalse($field);
}