php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13905 mysql_list_fields() fails
Submitted: 2001-11-01 22:10 UTC Modified: 2001-11-02 00:40 UTC
From: ub at shore dot net Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.0.4pl1 OS: RedHat Linux 7.1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ub at shore dot net
New email:
PHP Version: OS:

 

 [2001-11-01 22:10 UTC] ub at shore dot net
When running a simple query using the mysql_list_fields() function, I get an error no. 1064.

Below:
1. HTML output
2. code I used to produce the error
3. Table definition from mysql

1. HTML output
--------------
All's fine here: $query = 'mysql_list_fields('vocmaster_db','nouns_dehd',Resource id #1)'
safe_query: $query = mysql_list_fields('vocmaster_db','nouns_dehd',Resource id #1)

Query failed: 
errorno = 1064 
error = You have an error in your SQL syntax near 'mysql_list_fields('vocmaster_db','nouns_dehd',Resource id #1)' at line 1 
query = mysql_list_fields('vocmaster_db','nouns_dehd',Resource id #1) 
page = 


2. Code
-------
function get_table_fields($database="",$table="",$debug)
{
  $link=mysql_connect("localhost","root","");

  if(empty($table) or empty($database))
  {
    return FALSE;
  }
  $query = "mysql_list_fields('vocmaster_db','nouns_dehd',$link)";
  echo("All's fine here: \$query = '$query'");
  $result = safe_query($query,$debug);

  $num_fields = mysql_num_fields($result);
  echo "Table '$table' contains $num_fields fields:<ol>";
  for ($i=0; $i < $num_fields; ++$i)
  {
    echo ("<li> mysql_field_name($result,$i) </li>");
  }
  echo("</ol>");
}


function safe_query ($query="",$debug)
{
  echo("safe_query: \$query = $query");
  if($debug)
  {
    if (empty($query))
    {
      return FALSE;
    }
    $result = mysql_query($query)
      or die("<br> Query failed: "
        ."<ul>"
        ."  <li> errorno = " . mysql_errno()
        ."  <li> error = "   . mysql_error()
        ."  <li> query = "   . $query
        ."  <li> page = "    . $PHP_SELF
        ."</ul>"
        );
  } else {
    if (empty($query))
    {
      return FALSE;
    }
    $result = mysql_query($query)
      or die("Query failed. Please contact the webmaster.");
  }
  return $result;
}


3. table definition from mysql
------------------------------
mysql> describe nouns_dehd;
+------------+-------------------+------+-----+---------+----------------+
| Field      | Type              | Null | Key | Default | Extra          |
+------------+-------------------+------+-----+---------+----------------+
| id         | int(6) unsigned   |      | PRI | NULL    | auto_increment |
| singular   | varchar(25)       |      |     |         |                |
| plural     | varchar(25)       |      |     |         |                |
| gender     | enum('m','f','n') |      |     | m       |                |
| definition | varchar(250)      | YES  |     | NULL    |                |
+------------+-------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-02 00:40 UTC] sniper@php.net
Your script is buggy. Not a PHP bug -> Bogus.
Ask support questions on the mailing lists:

http://www.php.net/support.php

--Jani

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 20:01:30 2025 UTC