List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:September 18 1999 5:23pm
Subject:Re: in php: mysql_list_fields doesn't
View as plain text  
At 10:30 AM -0500 9/18/99, Seth Tager wrote:
>I'm trying to convert code from using msql to mysql and a call to
>mysql_list_fields, which worked in msql doesn't seem to work in mysql.
>The function is returning an empty result set when I
>know the fields exist in the mysql database. Any clue as to why
>it's not working the way I expect?
>
>One clue may (or may not) be that the result vector returned
>from mysql_list_fields is the same for different tables. That
>seems strange, but I have no idea how those numbers are generated
>internally. Here's the code followed by two different outputs.
>
>printf ("list fields in = %s<p>", $tableName );
>$result = mysql_list_fields("mydb", $tableName);
>printf ("result = %s<p>", $result );
>$error = mysql_error();
>if ($error) {
>  printf ("Error reading table %s fields! (%s)<p>", $tableName, $error );
>}
>else {
>  $i = 0;
>  $numfields = mysql_num_fields($result);
>  printf ("numfields = %s<p>", $numfields );
>  while ($i < $numfields) {
>    etc...

mysql_list_fields() doesn't return a result set that's like the one
returned by mysql_list_dbs() or mysql_list_tables().  Well, it does, but
the result set is always empty.  What you do instead is access the
column metadata information to get what you want.  Here's some sample
code.  The functions inside the loop are the ones that you can use
with the result set returned by mysql_list_fields().

    $result = mysql_list_fields ("samp_db", "member")
        or die ("Query failed");
    print ("member table column information:<BR>\n");
    for ($i = 0; $i < mysql_num_fields ($result); $i++)
    {
        printf ("column %d:", $i);
        printf (" name %s,\n", mysql_field_name ($result, $i));
        printf (" len %d,\n", mysql_field_len ($result, $i));
        printf (" type %s,\n", mysql_field_type ($result, $i));
        printf (" flags %s\n", mysql_field_flags ($result, $i));
        print "<BR>\n";
    }

--
Paul DuBois, paul@stripped
Thread
in php: mysql_list_fields doesn'tSeth Tager18 Sep
  • Re: in php: mysql_list_fields doesn'tPaul DuBois18 Sep
    • Re: in php: mysql_list_fields doesn'tSeth Tager18 Sep
      • Re: in php: mysql_list_fields doesn'tPaul DuBois18 Sep
        • Re: in php: mysql_list_fields doesn'tSeth Tager18 Sep
          • Re: in php: mysql_list_fields doesn'tMichael Widenius19 Sep
            • Re: in php: mysql_list_fields doesn'tSeth Tager20 Sep