]> granicus.if.org Git - php/commitdiff
MFH: Fix #47438 mysql_fetch_field ignores zero offse
authorJohannes Schlüter <johannes@php.net>
Wed, 18 Feb 2009 16:34:47 +0000 (16:34 +0000)
committerJohannes Schlüter <johannes@php.net>
Wed, 18 Feb 2009 16:34:47 +0000 (16:34 +0000)
NEWS
ext/mysql/php_mysql.c
ext/mysql/tests/bug47438.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index d29a71cb7e4a733575ea44bb9cf62036e5081d32..fb4d0fdfed5a9828d5c34fd39e650cc7d9451e5d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ PHP                                                                        NEWS
 ?? ??? 2009, PHP 5.3.0 Beta 2
 - Upgraded bundled sqlite to version 3.6.11. (Scott)
 
+- Fixed bug #47438 (mysql_fetch_field ignores zero offset). (Johannes)
 - Fixed bug #47398 (PDO_Firebird doesn't implements quoter correctly). (Felipe)
 - Fixed bug #47390 (odbc_fetch_into - BC in php 5.3.0). (Felipe)
 - Fixed bug #47343 (gc_collect_cycles causes a segfault when called within a
index b7fd650446e93d6fb902f75b9626f5e648107808..56301d9b152f8bbb1f8d6507b8a0ed847de97ce7 100644 (file)
@@ -2318,7 +2318,7 @@ PHP_FUNCTION(mysql_fetch_field)
        
        ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, &result, -1, "MySQL result", le_result);
 
-       if (field) {
+       if (ZEND_NUM_ARGS() > 1) {
                if (field<0 || field>=(int)mysql_num_fields(mysql_result)) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad field offset");
                        RETURN_FALSE;
diff --git a/ext/mysql/tests/bug47438.phpt b/ext/mysql/tests/bug47438.phpt
new file mode 100644 (file)
index 0000000..b646b9b
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+Bug #47438 mysql_fetch_field ignores zero offset
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+require_once('connect.inc');
+
+if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
+        printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
+                $host, $user, $db, $port, $socket);
+
+mysql_connect("localhost", "root", "");
+mysql_select_db("test");
+mysql_query("DROP TABLE IF EXISTS test_47438");
+mysql_query("CREATE TABLE test_47438 (a INT, b INT, c INT)");
+mysql_query("INSERT INTO test_47438 VALUES (10, 11, 12), (20, 21, 22)"); 
+$result = mysql_query("SELECT * FROM test_47438");
+mysql_field_seek($result, 1);
+
+$i = 0;
+
+while($i<mysql_num_fields($result))
+{
+  $meta=mysql_fetch_field($result,$i);
+  echo $i . "." . $meta->name . "\n";
+  $i++;
+}
+
+mysql_query("DROP TABLE IF EXISTS test_47438");
+
+?>
+--EXPECT--
+0.a
+1.b
+2.c