php.net |  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
Votes:2
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
Have you experienced this issue?
Rate the importance of this bug to you:

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


Reproduce code:
---------------
(mysql database table definition)
CREATE TABLE foo (
  some_value VARCHAR(50) DEFAULT 'blah'
);


(PHP Code)
<?php
$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);
    }
    $result->close();
}

/* close connection */
$mysqli->close();
?>

Expected result:
----------------
Default Value: blah

Actual result:
--------------
Default Value:

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-20 09:05 UTC] jani@php.net
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] andrey@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC