php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50685 mysql_list_fields deprecated
Submitted: 2010-01-07 14:19 UTC Modified: 2010-01-07 20:32 UTC
From: damir21 at hotmail dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.2.12 OS: Win 7
Private report: No CVE-ID: None
 [2010-01-07 14:19 UTC] damir21 at hotmail dot com
Description:
------------
I am trying to fetch a complete mySQL table schema and I found a great function in between the comments for the mysql_fetch_field function.

On the documentation page for mysql_fetch_field function you are using $result handle like this

$result = mysql_query('select * from table');
....
$meta = mysql_fetch_field($result, $i);

The problem is, that the $meta->def value is ALWAYS empty.
The problem is also noted here:
http://www.phpdig.net/ref/rn41re784.html

Te only way it works is if I use a deprecated function (mysql_list_fields()) like this:

$result = mysql_list_fields ($dbname, $tablename);
....
$meta = mysql_fetch_field($result, $i);

in this case the $meta->def is populated correctly!

Please make it clear in the documentations OR make it work correctly with you preffered method:
$result = mysql_query('select * from table');

best regards


Reproduce code:
---------------
---
From manual page: function.mysql_fetch_field#Examples
---
<?php
mysql_connect("127.0.0.1","nobody","");
$result = mysql_query('select * from table');
//...
$meta = mysql_fetch_field($result, 0);
echo $meta->def;
?>

Expected result:
----------------
0

Actual result:
--------------
null

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-07 20:32 UTC] jani@php.net
RTFM: "This function is deprecated. It is preferable to use mysql_query() to issue a SQL SHOW COLUMNS FROM table [LIKE 'name'] statement instead. "

And the correct manual page is here:

http://php.net/mysql_list_fields
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 11:01:30 2024 UTC