Moved deprecation note towards the top, rewrote example to use alternative

(undeprecated) means, and added see also's.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@163847 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2004-07-21 05:08:12 +00:00
parent 24f10c9ab4
commit 282d50a1e4

View file

@ -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 @@ field3
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>