Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You dont need an additional SQL query just to get your field names. You can use your normale SELECT query and just get your field names (and definition) from that query. Better performance this way!</p> <p><em>Deprecated MySQL Solution:</em></p> <p>The MySQL Library is deprecated. It can be used as in this link, btu you should switch to the mysqli Library which is nearly identical when used proceduraly (second sample).</p> <p>htttp://www.php.net/manual/en/function.mysql-field-name.php</p> <p><strong>The OOP MySQLi Solution:</strong></p> <pre><code>$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5"; if ($result = $mysqli-&gt;query($query)) { /* Get field information for all columns */ while ($finfo = $result-&gt;fetch_field()) { printf("Name: %s\n", $finfo-&gt;name); printf("Table: %s\n", $finfo-&gt;table); printf("max. Len: %d\n", $finfo-&gt;max_length); printf("Flags: %d\n", $finfo-&gt;flags); printf("Type: %d\n\n", $finfo-&gt;type); } $result-&gt;close(); } </code></pre> <p><strong>The Procedural MySQLi Solution:</strong></p> <pre><code>$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5"; if ($result = mysqli_query($link, $query)) { /* Get field information for all fields */ while ($finfo = mysqli_fetch_field($result)) { printf("Name: %s\n", $finfo-&gt;name); printf("Table: %s\n", $finfo-&gt;table); printf("max. Len: %d\n", $finfo-&gt;max_length); printf("Flags: %d\n", $finfo-&gt;flags); printf("Type: %d\n\n", $finfo-&gt;type); } mysqli_free_result($result); } </code></pre> <p><a href="http://www.php.net/manual/en/mysqli-result.fetch-field.php" rel="nofollow">http://www.php.net/manual/en/mysqli-result.fetch-field.php</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload