Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MFH: Fix #47438 mysql_fetch_field ignores zero offse

  • Loading branch information...
commit b489d3a69fcea9c8a79cb0cf00a09f8d9fd7d058 1 parent 42bb8ed
Johannes Schlüter authored February 18, 2009
1  NEWS
@@ -3,6 +3,7 @@ PHP                                                                        NEWS
3 3
 ?? ??? 2009, PHP 5.3.0 Beta 2
4 4
 - Upgraded bundled sqlite to version 3.6.11. (Scott)
5 5
 
  6
+- Fixed bug #47438 (mysql_fetch_field ignores zero offset). (Johannes)
6 7
 - Fixed bug #47398 (PDO_Firebird doesn't implements quoter correctly). (Felipe)
7 8
 - Fixed bug #47390 (odbc_fetch_into - BC in php 5.3.0). (Felipe)
8 9
 - Fixed bug #47343 (gc_collect_cycles causes a segfault when called within a
2  ext/mysql/php_mysql.c
@@ -2318,7 +2318,7 @@ PHP_FUNCTION(mysql_fetch_field)
2318 2318
 	
2319 2319
 	ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, &result, -1, "MySQL result", le_result);
2320 2320
 
2321  
-	if (field) {
  2321
+	if (ZEND_NUM_ARGS() > 1) {
2322 2322
 		if (field<0 || field>=(int)mysql_num_fields(mysql_result)) {
2323 2323
 			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad field offset");
2324 2324
 			RETURN_FALSE;
39  ext/mysql/tests/bug47438.phpt
... ...
@@ -0,0 +1,39 @@
  1
+--TEST--
  2
+Bug #47438 mysql_fetch_field ignores zero offset
  3
+--SKIPIF--
  4
+<?php
  5
+require_once('skipif.inc');
  6
+require_once('skipifconnectfailure.inc');
  7
+?>
  8
+--FILE--
  9
+<?php
  10
+require_once('connect.inc');
  11
+
  12
+if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
  13
+        printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  14
+                $host, $user, $db, $port, $socket);
  15
+
  16
+mysql_connect("localhost", "root", "");
  17
+mysql_select_db("test");
  18
+mysql_query("DROP TABLE IF EXISTS test_47438");
  19
+mysql_query("CREATE TABLE test_47438 (a INT, b INT, c INT)");
  20
+mysql_query("INSERT INTO test_47438 VALUES (10, 11, 12), (20, 21, 22)"); 
  21
+$result = mysql_query("SELECT * FROM test_47438");
  22
+mysql_field_seek($result, 1);
  23
+
  24
+$i = 0;
  25
+
  26
+while($i<mysql_num_fields($result))
  27
+{
  28
+  $meta=mysql_fetch_field($result,$i);
  29
+  echo $i . "." . $meta->name . "\n";
  30
+  $i++;
  31
+}
  32
+
  33
+mysql_query("DROP TABLE IF EXISTS test_47438");
  34
+
  35
+?>
  36
+--EXPECT--
  37
+0.a
  38
+1.b
  39
+2.c

0 notes on commit b489d3a

Please sign in to comment.
Something went wrong with that request. Please try again.