|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [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>
....
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 19:00:02 2025 UTC | 
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