php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39892 fetch_fields / fetch_field_direct
Submitted: 2006-12-19 21:23 UTC Modified: 2007-01-21 19:31 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: migues at email dot cz Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.2.0 OS: Win XP Pro SP2
Private report: No CVE-ID: None
 [2006-12-19 21:23 UTC] migues at email dot cz
Description:
------------
MySQL version: 5.0.27

def column for fetch_fields / fetch_field_direct is empty even if default values are set 

Reproduce code:
---------------
$arrfields=$res->fetch_fields();
 for ($i=0;$i<$res->field_count;$i++)
 {
 		
// /*OR */		foreach ($arrfields as $arrname=>$arrfld)
 			//{
 				
 			$arrfld=$res->fetch_field_direct($i);
 			$fldinfo->appendChild($fldNode=$this->DOM->createElement(dbtag_field));
 			$fldNode->setAttribute(dbtag_fieldname,$arrfld->name);
 			$fldNode->setAttribute(dbtag_fieldorgname,$arrfld->orgname);	
 			foreach($arrfld as $key=>$val)
 			{
 			$fldNode->appendChild($this->DOM->createElement($key,$val));	
 			}};

Expected result:
----------------
<name>fieldname</name>
....
<def>default _ value</def>
....

Actual result:
--------------
<name>fieldname</name>
....
<def></def>
....

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-19 21:37 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2006-12-19 21:56 UTC] migues at email dot cz
Hey guys!

Sorry I'm quite novice so it would took me long time to reproduce step by step creation a.s.o.

But it's simple :
def $res->fetch_fields(); in returns always null! I guess it will work always the same on other mysql 5.0... with mysqli_result object
 [2006-12-19 22:21 UTC] tony2001@php.net
It might become really simple as soon as I get what you're talking about.
At the moment I don't get it, sorry.
 [2006-12-27 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2007-01-17 21:43 UTC] ceabear at gmx dot de
Here is a quick example code for the original bug report,
it should print the column name and its defined default value for the column.

<?php
$sql="CREATE TABLE `fetchfield` (
  `id` int(11) NOT NULL auto_increment,
  `product` varchar(11) collate latin1_german1_ci NOT NULL default 'standard',
  `test` int(11) default '3',
  `nullable` int(11) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM;";

	$con=mysqli_connect('localhost','username','password','test');
	mysqli_query($con,$sql);
	
	$res=mysqli_query($con,"SELECT * FROM test.fetchfield");
	$metas=mysqli_fetch_fields($res);
	foreach($metas as $meta)
		{
		echo 'default for '.$meta->name.' is:';
		var_dump($meta->def);
		echo '<br>';
		}
?>

this creates a simple test table with some fields, which get default values by definition.

as a result I get:
default for id is:string(0) ""
default for product is:string(0) ""
default for test is:string(0) ""
default for nullable is:string(0) ""

the column names are printed ($meta-name) but the default value ($meta->def) is always an empty string.

expected output is:
default for id is:string(0) ""
default for product is:string(0) "standard"
default for test is:string(0) "3"
default for nullable is:string(0) null

it looks like the default value is always an empty string instead of data out of the database.

looking into the source of php, a null value would be never returned (because of the source code).

I tried to find out, if this could be a problem of the c-api of mysql, but didn't find a fitting bug entry on mysql.

maybe this helps to understand the problem?

I used mysql version 5.0.21-community-nt-log on Windows 2000 SP4 and PHP 5.2.0 for testing
 [2007-01-18 08:01 UTC] migues at email dot cz
Thanks to Christian and his example code, status can be changed to open again.
 [2007-01-21 19:31 UTC] iliaa@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

The problem here is that the mysql mysql_fetch_field_direct() 
function fails to populate the "def" property of the 
MYSQL_FIELD structure. This subsequently causes PHP to put an 
empty string for its value.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 29 17:01:31 2024 UTC