Bug #21569 mysqli_fetch_fields doesn't return fields' default values
Submitted: 10 Aug 2006 16:25 Modified: 15 Aug 2006 10:06
Reporter: Filipe Martins Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5-5.024 OS:Windows (Windows XP SP2)
Assigned to: CPU Architecture:Any
Tags: field default value, mysqli_fetch_fields

[10 Aug 2006 16:25] Filipe Martins
Description:
Greetings.

I tried to use mysqli_fetch_fields in PHP5 to retrieve the metadata about a resultset. I can get all the props except the default value of each field. The DEF prop always returns NULL.

I'm using:
* PHP 5.0.22
* MySQL 5.0.24
* client libs 5.1.4 (downloaded from Mysql.com - php_5.1.4_mysqli_5.0.22-win32.zip)

Notice that this already happened in older versions of MySQL 5. I just updated all the software to test that the problem remains.

Here is the output I get from the script bellow:

VER: 5.0.22

IdCli    def:
Nome    def:
CP    def:
DataNasc    def:
NumContrib    def:
xxx    def:
Elim?    def: 

Thank you. If I can help further please contact me.
Filipe Martins
http://www.i-senso.com

How to repeat:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">

h2 {	margin:1.5em 0 0.2em 0;	}

</style>
<title>teste mysql</title>
</head>

<body>
<?php
echo 'VER: ' . mysqli_get_client_info () . '<br /><br />';

// Connect.
$link = mysqli_connect("localhost", "root", "36981613", "test");
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
// Create table.
$sql = "
CREATE TABLE `clientes` (
  `IdCli` int(11) NOT NULL auto_increment,
  `Nome` varchar(50) default 'abc',
  `CP` int(11) default '4590',
  `DataNasc` datetime default NULL,
  `NumContrib` double default NULL,
  `xxx` mediumblob,
  `Elim?` bit(1) default NULL,
  PRIMARY KEY  (`IdCli`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
";
if (!mysqli_query ($link, 'DROP TABLE IF EXISTS Clientes') || !mysqli_query ($link, $sql)) {
	echo 'ERROR - ' . mysqli_error ($link);
	die ();
}
// Get the fields.
$res = mysqli_query ($link, 'SELECT * FROM CLIENTES');
if (!$res) {
	echo 'ERROR - ' . mysqli_error ($link);
	die ();
}
$flds = mysqli_fetch_fields ($res);
foreach ($flds as $fld) {
	echo $fld->name . '&nbsp;&nbsp;&nbsp;&nbsp;def: ' . $fld->def . '<br />';
}

?>
</body>
</html>
[10 Aug 2006 16:44] Paul DuBois
See: http://dev.mysql.com/doc/refman/5.0/en/c-api-datatypes.html, which
describes the metadata for result sets:

char * def

The default value of this field, as a null-terminated string. This is set only if you use mysql_list_fields().
[15 Aug 2006 10:06] Sveta Smirnova
Thank you for the report. But it is not our bug. Please, report it at http://bugs.php.net