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 . ' def: ' . $fld->def . '<br />';
}
?>
</body>
</html>