cvs: phpdoc /it/functions mysql.xml
| From: | Luca Perugini | Date: | Tue, 09 Jan 2001 18:29:21 +0000 |
| Subject: | cvs: phpdoc /it/functions mysql.xml | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969333515@lists.php.net to get a copy of this message | ||
perugini Tue Jan 9 10:29:21 2001 EDT
Modified files:
/phpdoc/it/functions mysql.xml
Log:
Sync with en tree.
Index: phpdoc/it/functions/mysql.xml
diff -u phpdoc/it/functions/mysql.xml:1.6 phpdoc/it/functions/mysql.xml:1.7
--- phpdoc/it/functions/mysql.xml:1.6 Thu Sep 14 15:49:08 2000
+++ phpdoc/it/functions/mysql.xml Tue Jan 9 10:29:21 2001
@@ -399,7 +399,7 @@
$db_list = mysql_list_dbs();
$i = 0;
-$cnt = mysql_numrows($db_list);
+$cnt = mysql_num_rows($db_list);
while ($i < $cnt) {
echo mysql_db_name($db_list, $i) . "\n";
$i++;
@@ -593,7 +593,7 @@
<refnamediv>
<refname>mysql_fetch_array</refname>
<refpurpose>
- Fetch a result row as an associative array
+ Fetch a result row as an associative array, a numeric array, or both.
</refpurpose>
</refnamediv>
<refsect1>
@@ -643,15 +643,76 @@
</para>
<para>
For further details, see also
- <function>mysql_fetch_row</function>.
+ <function>mysql_fetch_row</function> and
<function>mysql_fetch_assoc</function>.
</para>
<example>
<title><function>Mysql_fetch_array</function></title>
<programlisting role="php">
<?php
mysql_connect ($host, $user, $password);
-$result = mysql_db_query ("database","select * from table");
+$result = mysql_db_query ("database","select user_id, fullname from table");
while ($row = mysql_fetch_array ($result)) {
+ echo "user_id: ".$row["user_id"]."<br>\n";
+ echo "user_id: ".$row[0]."<br>\n";
+ echo "fullname: ".$row["fullname"]."<br>\n";
+ echo "fullname: ".$row[1]."<br>\n";
+}
+mysql_free_result ($result);
+?>
+ </programlisting>
+ </example>
+ </refsect1>
+ </refentry>
+
+ <refentry id="function.mysql-fetch-assoc">
+ <refnamediv>
+ <refname>mysql_fetch_assoc</refname>
+ <refpurpose>
+ Fetch a result row as an associative array
+ </refpurpose>
+ </refnamediv>
+ <refsect1>
+ <title>Description</title>
+ <funcsynopsis>
+ <funcprototype>
+ <funcdef>array <function>mysql_fetch_assoc</function></funcdef>
+ <paramdef>int <parameter>result</parameter></paramdef>
+ </funcprototype>
+ </funcsynopsis>
+ <para>
+ Returns an associative array that corresponds to the fetched row,
+ or false if there are no more rows.</para>
+ <para>
+ <function>mysql_fetch_assoc</function> is equivalent to calling
+ <function>mysql_fetch_array</function> with MYSQL_ASSOC for the
+ optional second parameter. It only returns an associative array.
+ This is the way <function>mysql_fetch_array</function> originally
+ worked. If you need the numeric indices as well as the
+ associative, use <function>mysql_fetch_array</function>.
+ </para>
+ <para>
+ If two or more columns of the result have the same field names,
+ the last column will take precedence. To access the other column(s)
+ of the same name, you must use <function>mysql_fetch_array</function> and
+ have it return the numeric indices as well.
+ </para>
+ <para>
+ An important thing to note is that using
+ <function>mysql_fetch_assoc</function> is NOT significantly
+ slower than using <function>mysql_fetch_row</function>, while it
+ provides a significant added value.
+ </para>
+ <para>
+ For further details, see also
+ <function>mysql_fetch_row</function> and
<function>mysql_fetch_array</function>.
+ </para>
+ <example>
+ <title><function>Mysql_fetch_assoc</function></title>
+ <programlisting role="php">
+<?php
+mysql_connect ($host, $user, $password);
+$result = mysql_db_query ("database","select * from table");
+while ($row = mysql_fetch_assoc ($result)) {
echo $row["user_id"];
echo $row["fullname"];
}
@@ -1463,6 +1524,22 @@
a result set. This command is only valid for SELECT statements.
To retrieve the number of rows returned from a INSERT, UPDATE or
DELETE, use <function>mysql_affected_rows</function>.
+ <example>
+ <title>
+ <function>
+ mysql_num_rows example by crubel@trilizio.org
+ </function>
+ </title>
+ <programlisting role="php">
+<?php
+$conn = mysql_connect("hostaddress", "username", "password");
+mysql_select_db("database",$conn); // needed if you have m,ultiple db's
+$Resultfornummembers = mysql_query("SELECT * FROM Accounts",$conn);
+$NumMembers = mysql_num_rows($Resultfornummembers);
+echo "$NumMembers Members";
+?>
+ </programlisting>
+ </example>
</para>
<para>
See also: