philip          Wed Jul 21 01:08:12 2004 EDT

  Modified files:              
    /phpdoc/en/reference/mysql/functions        mysql-list-fields.xml 
  Log:
  Moved deprecation note towards the top, rewrote example to use alternative
  (undeprecated) means, and added see also's.
  
  
http://cvs.php.net/diff.php/phpdoc/en/reference/mysql/functions/mysql-list-fields.xml?r1=1.7&r2=1.8&ty=u
Index: phpdoc/en/reference/mysql/functions/mysql-list-fields.xml
diff -u phpdoc/en/reference/mysql/functions/mysql-list-fields.xml:1.7 
phpdoc/en/reference/mysql/functions/mysql-list-fields.xml:1.8
--- phpdoc/en/reference/mysql/functions/mysql-list-fields.xml:1.7       Thu Dec 11 
10:42:01 2003
+++ phpdoc/en/reference/mysql/functions/mysql-list-fields.xml   Wed Jul 21 01:08:12 
2004
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.7 $ -->
+<!-- $Revision: 1.8 $ -->
 <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
   <refentry id="function.mysql-list-fields">
    <refnamediv>
@@ -16,6 +16,13 @@
         link_identifier
        </parameter></methodparam>
      </methodsynopsis>
+    <note>
+     <para>
+      The function <function>mysql_list_fields</function> is deprecated. It
+      is preferable to use <function>mysql_query</function> to issue a
+      SQL <literal>SHOW COLUMNS FROM table [LIKE 'name']</literal> Statement instead.
+     </para>
+    </note>
     <para>
      <function>mysql_list_fields</function> retrieves information
      about the given table name. Arguments are the database and
@@ -27,30 +34,46 @@
     </para>
     <para>
      <example>
-      <title><function>mysql_list_fields</function> example</title>
+      <title>Alternate to deprecated <function>mysql_list_fields</function></title>
       <programlisting role="php">
 <![CDATA[
 <?php
-$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
-
-$fields = mysql_list_fields("database1", "table1", $link);
-$columns = mysql_num_fields($fields);
-
-for ($i = 0; $i < $columns; $i++) {
-    echo mysql_field_name($fields, $i) . "\n";
+$result = mysql_query("SHOW COLUMNS FROM sometable");
+if (!$result) {
+    echo 'Could not run query: ' . mysql_error();
+    exit;
+}
+if (mysql_num_rows($result) > 0) {
+    while ($row = mysql_fetch_assoc($result)) {
+        print_r($row);
+    }
 }
 ?>
 ]]>
       </programlisting>
       <para>
-       The above example would produce the following output:
+       The above example would produce output similar to:
       </para>
       <screen>
 <![CDATA[
-field1
-field2
-field3
-...
+Array
+(
+    [Field] => id
+    [Type] => int(7)
+    [Null] =>
+    [Key] => PRI
+    [Default] =>
+    [Extra] => auto_increment
+)
+Array
+(
+    [Field] => email
+    [Type] => varchar(100)
+    [Null] =>
+    [Key] =>
+    [Default] =>
+    [Extra] =>
+)
 ]]>
       </screen>
      </example>
@@ -59,13 +82,11 @@
      For downward compatibility <function>mysql_listfields</function>
      can also be used. This is deprecated however.
     </para>
-    <note>
-     <para>
-      The function <function>mysql_list_fields</function> is deprecated. It
-      is preferable to use <function>mysql_query</function> to issue a
-      SQL <literal>SHOW COLUMNS FROM table [LIKE 'name']</literal> Statement instead.
-     </para>
-    </note>
+    <para>
+     See also
+     <function>mysql_field_flags</function> and
+     <function>mysql_info</function>.
+    </para>
    </refsect1>
   </refentry>
 

Reply via email to