|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42344 fetch_field() does not aggregate default value
Submitted: 2007-08-20 05:33 UTC Modified: 2007-08-20 22:31 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: php at michaelho dot com Assigned:
Status: Wont fix Package: MySQLi related
PHP Version: 5.2.3 OS: Mac OS X 10.4.9
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php at michaelho dot com
New email:
PHP Version: OS:


 [2007-08-20 05:33 UTC] php at michaelho dot com
The object returned from MySQLi's fetch_field() does not ever aggregate the ->def value.

Reproduce code:
(mysql database table definition)
  some_value VARCHAR(50) DEFAULT 'blah'

(PHP Code)
$mysqli = new mysqli("localhost", "root", "", "test");

$query = "SELECT * from foo";

if ($result = $mysqli->query($query)) {
    /* Get field information for all columns */
    while ($finfo = $result->fetch_field()) {
        printf("Default Value: %s\n", $finfo->def);

/* close connection */

Expected result:
Default Value: blah

Actual result:
Default Value:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-20 09:05 UTC]
This is very simple function which just wraps around the provided libmysql function 'mysql_fetch_field' and pretty much can't be a bug on the PHP side. What mysql version have you compiled PHP with?
 [2007-08-20 13:49 UTC]
The empty string comes from libmysql, but also mysqlnd doesn't have a solution as the data is not transfered with the meta-data for the columns.
A comment in mysqlnd reveals more :
	char *def;	/* Default value (set by mysql_list_fields) */

mysql_list_fields uses COM_FIELD_LIST, from the C/S protocol. Only in this case the default value is sent. If you want to get it, you need to issue SHOW FIELDS FROM or a query against INFORMATION_SCHEMA.

 [2007-08-20 22:31 UTC] php at michaelho dot com
Thanks for the note.

I suggest that the documentation be updated to reflect this to avoid future confusion.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Dec 06 15:03:34 2021 UTC