cvs: phpdoc /en/reference/mysql reference.xml /en/reference/mysql/functions mysql-affected-rows.xml mysql-close.xml mysql-connect.xml
mysql-create-db.xml mysql-data-seek.xml mysql-db-name.xml mysql-drop-db.xml mysql-errno.xml mysql-error.xml mysql-escape-string.xml
mysql-fetch-array.xml mysql-fetch-assoc.xml mysql-get-client-info.xml mysql-get-host-info.xml mysql-get-proto-info.xml mysql-get-server-info.xml
mysql-insert-id.xml mysql-list-tables.xml mysql-query.xml mysql-result.xml mysql-select-db.xml mysql-tablename.xml

From: Date: Mon, 05 Jan 2004 13:03:26 +0000
Subject: cvs: phpdoc /en/reference/mysql reference.xml /en/reference/mysql/functions mysql-affected-rows.xml mysql-close.xml mysql-connect.xml
mysql-create-db.xml mysql-data-seek.xml mysql-db-name.xml mysql-drop-db.xml mysql-errno.xml mysql-error.xml mysql-escape-string.xml
mysql-fetch-array.xml mysql-fetch-assoc.xml mysql-get-client-info.xml mysql-get-host-info.xml mysql-get-proto-info.xml mysql-get-server-info.xml
mysql-insert-id.xml mysql-list-tables.xml mysql-query.xml mysql-result.xml mysql-select-db.xml mysql-tablename.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969357942@lists.php.net to get a copy of this message
betz Mon Jan 5 08:03:26 2004 EDT Modified files: /phpdoc/en/reference/mysql reference.xml /phpdoc/en/reference/mysql/functions mysql-affected-rows.xml mysql-close.xml mysql-connect.xml mysql-create-db.xml mysql-data-seek.xml mysql-db-name.xml mysql-drop-db.xml mysql-errno.xml mysql-error.xml mysql-escape-string.xml mysql-fetch-array.xml mysql-fetch-assoc.xml mysql-get-client-info.xml mysql-get-host-info.xml mysql-get-proto-info.xml mysql-get-server-info.xml mysql-insert-id.xml mysql-list-tables.xml mysql-query.xml mysql-result.xml mysql-select-db.xml mysql-tablename.xml Log: examples start at col 0

Index: phpdoc/en/reference/mysql/reference.xml diff -u phpdoc/en/reference/mysql/reference.xml:1.17 phpdoc/en/reference/mysql/reference.xml:1.18 --- phpdoc/en/reference/mysql/reference.xml:1.17 Mon Dec 15 11:52:06 2003 +++ phpdoc/en/reference/mysql/reference.xml Mon Jan 5 08:03:25 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.17 $ --> +<!-- $Revision: 1.18 $ --> <reference id="ref.mysql"> <title>MySQL Functions</title> <titleabbrev>MySQL</titleabbrev> @@ -52,32 +52,32 @@ <programlisting role="php"> <![CDATA[ <?php - /* Connecting, selecting database */ - $link = mysql_connect("mysql_host", "mysql_user", "mysql_password") - or die("Could not connect : " . mysql_error()); - echo "Connected successfully"; - mysql_select_db("my_database") or die("Could not select database"); - - /* Performing SQL query */ - $query = "SELECT * FROM my_table"; - $result = mysql_query($query) or die("Query failed : " . mysql_error()); - - /* Printing results in HTML */ - echo "<table>\n"; - while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { - echo "\t<tr>\n"; - foreach ($line as $col_value) { - echo "\t\t<td>$col_value</td>\n"; - } - echo "\t</tr>\n"; +/* Connecting, selecting database */ +$link = mysql_connect("mysql_host", "mysql_user", "mysql_password") + or die("Could not connect : " . mysql_error()); +echo "Connected successfully"; +mysql_select_db("my_database") or die("Could not select database"); + +/* Performing SQL query */ +$query = "SELECT * FROM my_table"; +$result = mysql_query($query) or die("Query failed : " . mysql_error()); + +/* Printing results in HTML */ +echo "<table>\n"; +while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { + echo "\t<tr>\n"; + foreach ($line as $col_value) { + echo "\t\t<td>$col_value</td>\n"; } - echo "</table>\n"; + echo "\t</tr>\n"; + } +echo "</table>\n"; - /* Free resultset */ - mysql_free_result($result); +/* Free resultset */ +mysql_free_result($result); - /* Closing connection */ - mysql_close($link); +/* Closing connection */ +mysql_close($link); ?> ]]> </programlisting> @@ -110,4 +110,3 @@ vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> - Index: phpdoc/en/reference/mysql/functions/mysql-affected-rows.xml diff -u phpdoc/en/reference/mysql/functions/mysql-affected-rows.xml:1.11 phpdoc/en/reference/mysql/functions/mysql-affected-rows.xml:1.12 --- phpdoc/en/reference/mysql/functions/mysql-affected-rows.xml:1.11 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-affected-rows.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.11 $ --> +<!-- $Revision: 1.12 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-affected-rows"> <refnamediv> @@ -56,18 +56,18 @@ <programlisting role="php"> <![CDATA[ <?php - /* connect to database */ - mysql_pconnect("localhost", "mysql_user", "mysql_password") or - die("Could not connect: " . mysql_error()); - mysql_select_db("mydb"); - - /* this should return the correct numbers of deleted records */ - mysql_query("DELETE FROM mytable WHERE id < 10"); - printf("Records deleted: %d\n", mysql_affected_rows()); +/* connect to database */ +mysql_pconnect("localhost", "mysql_user", "mysql_password") + or die("Could not connect: " . mysql_error()); +mysql_select_db("mydb"); - /* without a where clause in a delete statement, it should return 0 */ - mysql_query("DELETE FROM mytable"); - printf("Records deleted: %d\n", mysql_affected_rows()); +/* this should return the correct numbers of deleted records */ +mysql_query("DELETE FROM mytable WHERE id < 10"); +printf("Records deleted: %d\n", mysql_affected_rows()); + +/* without a where clause in a delete statement, it should return 0 */ +mysql_query("DELETE FROM mytable"); +printf("Records deleted: %d\n", mysql_affected_rows()); ?> ]]> </programlisting> @@ -88,15 +88,15 @@ <programlisting role="php"> <![CDATA[ <?php - /* connect to database */ - mysql_pconnect("localhost", "mysql_user", "mysql_password") or - die("Could not connect: " . mysql_error()); - mysql_select_db("mydb"); +/* connect to database */ +mysql_pconnect("localhost", "mysql_user", "mysql_password") or + die("Could not connect: " . mysql_error()); +mysql_select_db("mydb"); - /* Update records */ - mysql_query("UPDATE mytable SET used=1 WHERE id < 10"); - printf ("Updated records: %d\n", mysql_affected_rows()); - mysql_query("COMMIT"); +/* Update records */ +mysql_query("UPDATE mytable SET used=1 WHERE id < 10"); +printf ("Updated records: %d\n", mysql_affected_rows()); +mysql_query("COMMIT"); ?> ]]> </programlisting> @@ -111,7 +111,7 @@ </example> </para> <para> - See also <function>mysql_num_rows</function>, + See also <function>mysql_num_rows</function>, and <function>mysql_info</function>. </para> </refsect1> Index: phpdoc/en/reference/mysql/functions/mysql-close.xml diff -u phpdoc/en/reference/mysql/functions/mysql-close.xml:1.5 phpdoc/en/reference/mysql/functions/mysql-close.xml:1.6 --- phpdoc/en/reference/mysql/functions/mysql-close.xml:1.5 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-close.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-close"> <refnamediv> @@ -41,10 +41,10 @@ <programlisting role="php"> <![CDATA[ <?php - $link = mysql_connect("localhost", "mysql_user", "mysql_password") - or die("Could not connect: " . mysql_error()); - echo "Connected successfully"; - mysql_close($link); +$link = mysql_connect("localhost", "mysql_user", "mysql_password") + or die("Could not connect: " . mysql_error()); +echo "Connected successfully"; +mysql_close($link); ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-connect.xml diff -u phpdoc/en/reference/mysql/functions/mysql-connect.xml:1.9 phpdoc/en/reference/mysql/functions/mysql-connect.xml:1.10 --- phpdoc/en/reference/mysql/functions/mysql-connect.xml:1.9 Thu Dec 18 09:14:30 2003 +++ phpdoc/en/reference/mysql/functions/mysql-connect.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.9 $ --> +<!-- $Revision: 1.10 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-connect"> <refnamediv> @@ -99,10 +99,10 @@ <programlisting role="php"> <![CDATA[ <?php - $link = mysql_connect("localhost", "mysql_user", "mysql_password") - or die("Could not connect: " . mysql_error()); - echo "Connected successfully"; - mysql_close($link); +$link = mysql_connect("localhost", "mysql_user", "mysql_password") + or die("Could not connect: " . mysql_error()); +echo "Connected successfully"; +mysql_close($link); ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-create-db.xml diff -u phpdoc/en/reference/mysql/functions/mysql-create-db.xml:1.8 phpdoc/en/reference/mysql/functions/mysql-create-db.xml:1.9 --- phpdoc/en/reference/mysql/functions/mysql-create-db.xml:1.8 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-create-db.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-create-db"> <refnamediv> @@ -29,14 +29,14 @@ <programlisting role="php"> <![CDATA[ <?php - $link = mysql_pconnect("localhost", "mysql_user", "mysql_password") - or die("Could not connect: " . mysql_error()); +$link = mysql_connect("localhost", "mysql_user", "mysql_password") + or die("Could not connect: " . mysql_error()); - if (mysql_create_db("my_db")) { - echo "Database created successfully\n"; - } else { - echo "Error creating database: " . mysql_error() . "\n"; - } +if (mysql_create_db("my_db")) { + echo "Database created successfully\n"; +} else { + echo "Error creating database: " . mysql_error() . "\n"; +} ?> ]]> </programlisting> @@ -60,9 +60,7 @@ </para> </warning> <para> - See also - <function>mysql_drop_db</function> and - <function>mysql_query</function>. + See also <function>mysql_query</function>. </para> </refsect1> </refentry> Index: phpdoc/en/reference/mysql/functions/mysql-data-seek.xml diff -u phpdoc/en/reference/mysql/functions/mysql-data-seek.xml:1.7 phpdoc/en/reference/mysql/functions/mysql-data-seek.xml:1.8 --- phpdoc/en/reference/mysql/functions/mysql-data-seek.xml:1.7 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-data-seek.xml Mon Jan 5 08:03:26 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-data-seek"> <refnamediv> @@ -40,30 +40,30 @@ <programlisting role="php"> <![CDATA[ <?php - $link = mysql_pconnect("localhost", "mysql_user", "mysql_password") - or die("Could not connect: " . mysql_error()); +$link = mysql_connect("localhost", "mysql_user", "mysql_password") + or die("Could not connect: " . mysql_error()); - mysql_select_db("samp_db") - or die("Could not select database: " . mysql_error()); +mysql_select_db("samp_db") + or die("Could not select database: " . mysql_error()); - $query = "SELECT last_name, first_name FROM friends"; - $result = mysql_query($query) - or die("Query failed: " . mysql_error()); - - /* fetch rows in reverse order */ - for ($i = mysql_num_rows($result) - 1; $i >= 0; $i--) { - if (!mysql_data_seek($result, $i)) { - echo "Cannot seek to row $i: " . mysql_error() . "\n"; - continue; - } +$query = "SELECT last_name, first_name FROM friends"; +$result = mysql_query($query) + or die("Query failed: " . mysql_error()); + +/* fetch rows in reverse order */ +for ($i = mysql_num_rows($result) - 1; $i >= 0; $i--) { + if (!mysql_data_seek($result, $i)) { + echo "Cannot seek to row $i: " . mysql_error() . "\n"; + continue; + } - if (!($row = mysql_fetch_object($result))) - continue; + if (!($row = mysql_fetch_object($result))) + continue; - echo "$row->last_name $row->first_name<br />\n"; - } + echo "$row->last_name $row->first_name<br />\n"; +} - mysql_free_result($result); +mysql_free_result($result); ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-db-name.xml diff -u phpdoc/en/reference/mysql/functions/mysql-db-name.xml:1.3 phpdoc/en/reference/mysql/functions/mysql-db-name.xml:1.4 --- phpdoc/en/reference/mysql/functions/mysql-db-name.xml:1.3 Wed Jul 9 11:07:29 2003 +++ phpdoc/en/reference/mysql/functions/mysql-db-name.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.23 --> <refentry id="function.mysql-db-name"> <refnamediv> @@ -35,17 +35,17 @@ <programlisting role="php"> <![CDATA[ <?php - error_reporting(E_ALL); +error_reporting(E_ALL); - mysql_connect('dbhost', 'username', 'password'); - $db_list = mysql_list_dbs(); +$link = mysql_connect('dbhost', 'username', 'password'); +$db_list = mysql_list_dbs($link); - $i = 0; - $cnt = mysql_num_rows($db_list); - while ($i < $cnt) { - echo mysql_db_name($db_list, $i) . "\n"; - $i++; - } +$i = 0; +$cnt = mysql_num_rows($db_list); +while ($i < $cnt) { + echo mysql_db_name($db_list, $i) . "\n"; + $i++; +} ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-drop-db.xml diff -u phpdoc/en/reference/mysql/functions/mysql-drop-db.xml:1.8 phpdoc/en/reference/mysql/functions/mysql-drop-db.xml:1.9 --- phpdoc/en/reference/mysql/functions/mysql-drop-db.xml:1.8 Wed Jul 9 11:07:29 2003 +++ phpdoc/en/reference/mysql/functions/mysql-drop-db.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-drop-db"> <refnamediv> @@ -41,9 +41,7 @@ </para> </warning> <para> - See also - <function>mysql_create_db</function> and - <function>mysql_query</function>. + See also <function>mysql_query</function>. </para> </refsect1> </refentry> Index: phpdoc/en/reference/mysql/functions/mysql-errno.xml diff -u phpdoc/en/reference/mysql/functions/mysql-errno.xml:1.7 phpdoc/en/reference/mysql/functions/mysql-errno.xml:1.8 --- phpdoc/en/reference/mysql/functions/mysql-errno.xml:1.7 Wed Jul 9 11:07:29 2003 +++ phpdoc/en/reference/mysql/functions/mysql-errno.xml Mon Jan 5 08:03:26 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-errno"> <refnamediv> @@ -35,14 +35,14 @@ <programlisting role="php"> <![CDATA[ <?php - mysql_connect("localhost", "mysql_user", "mysql_password"); +$link = mysql_connect("localhost", "mysql_user", "mysql_password"); - mysql_select_db("nonexistentdb"); - echo mysql_errno() . ": " . mysql_error(). "\n"; +mysql_select_db("nonexistentdb", $link); +echo mysql_errno($link) . ": " . mysql_error($link). "\n"; - mysql_select_db("kossu"); - mysql_query("SELECT * FROM nonexistenttable"); - echo mysql_errno() . ": " . mysql_error() . "\n"; +mysql_select_db("kossu", $link); +mysql_query("SELECT * FROM nonexistenttable", $link); +echo mysql_errno($link) . ": " . mysql_error($link) . "\n"; ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-error.xml diff -u phpdoc/en/reference/mysql/functions/mysql-error.xml:1.10 phpdoc/en/reference/mysql/functions/mysql-error.xml:1.11 --- phpdoc/en/reference/mysql/functions/mysql-error.xml:1.10 Thu Dec 18 09:14:30 2003 +++ phpdoc/en/reference/mysql/functions/mysql-error.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.10 $ --> +<!-- $Revision: 1.11 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-error"> <refnamediv> @@ -37,14 +37,14 @@ <programlisting role="php"> <![CDATA[ <?php - mysql_connect("localhost", "mysql_user", "mysql_password"); +$link = mysql_connect("localhost", "mysql_user", "mysql_password"); - mysql_select_db("nonexistentdb"); - echo mysql_errno() . ": " . mysql_error(). "\n"; +mysql_select_db("nonexistentdb", $link); +echo mysql_errno($link) . ": " . mysql_error($link). "\n"; - mysql_select_db("kossu"); - mysql_query("SELECT * FROM nonexistenttable"); - echo mysql_errno() . ": " . mysql_error() . "\n"; +mysql_select_db("kossu", $link); +mysql_query("SELECT * FROM nonexistenttable", $link); +echo mysql_errno($link) . ": " . mysql_error($link) . "\n"; ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-escape-string.xml diff -u phpdoc/en/reference/mysql/functions/mysql-escape-string.xml:1.8 phpdoc/en/reference/mysql/functions/mysql-escape-string.xml:1.9 --- phpdoc/en/reference/mysql/functions/mysql-escape-string.xml:1.8 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-escape-string.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.62 --> <refentry id="function.mysql-escape-string"> <refnamediv> @@ -37,9 +37,9 @@ <programlisting role="php"> <![CDATA[ <?php - $item = "Zak's Laptop"; - $escaped_item = mysql_escape_string($item); - printf("Escaped string: %s\n", $escaped_item); +$item = "Zak's Laptop"; +$escaped_item = mysql_escape_string($item); +printf("Escaped string: %s\n", $escaped_item); ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-fetch-array.xml diff -u phpdoc/en/reference/mysql/functions/mysql-fetch-array.xml:1.12 phpdoc/en/reference/mysql/functions/mysql-fetch-array.xml:1.13 --- phpdoc/en/reference/mysql/functions/mysql-fetch-array.xml:1.12 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-fetch-array.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.12 $ --> +<!-- $Revision: 1.13 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.27 --> <refentry id="function.mysql-fetch-array"> <refnamediv> @@ -70,17 +70,17 @@ <programlisting role="php"> <![CDATA[ <?php - mysql_connect("localhost", "mysql_user", "mysql_password") or - die("Could not connect: " . mysql_error()); - mysql_select_db("mydb"); +mysql_connect("localhost", "mysql_user", "mysql_password") or + die("Could not connect: " . mysql_error()); +mysql_select_db("mydb"); - $result = mysql_query("SELECT id, name FROM mytable"); +$result = mysql_query("SELECT id, name FROM mytable"); - while ($row = mysql_fetch_array($result, MYSQL_NUM)) { - printf("ID: %s Name: %s", $row[0], $row[1]); - } +while ($row = mysql_fetch_array($result, MYSQL_NUM)) { + printf("ID: %s Name: %s", $row[0], $row[1]); +} - mysql_free_result($result); +mysql_free_result($result); ?> ]]> </programlisting> @@ -90,17 +90,17 @@ <programlisting role="php"> <![CDATA[ <?php - mysql_connect("localhost", "mysql_user", "mysql_password") or - die("Could not connect: " . mysql_error()); - mysql_select_db("mydb"); +mysql_connect("localhost", "mysql_user", "mysql_password") or + die("Could not connect: " . mysql_error()); +mysql_select_db("mydb"); - $result = mysql_query("SELECT id, name FROM mytable"); +$result = mysql_query("SELECT id, name FROM mytable"); - while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { - printf("ID: %s Name: %s", $row["id"], $row["name"]); - } +while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { + printf("ID: %s Name: %s", $row["id"], $row["name"]); +} - mysql_free_result($result); +mysql_free_result($result); ?> ]]> </programlisting> @@ -110,17 +110,17 @@ <programlisting role="php"> <![CDATA[ <?php - mysql_connect("localhost", "mysql_user", "mysql_password") or - die("Could not connect: " . mysql_error()); - mysql_select_db("mydb"); +mysql_connect("localhost", "mysql_user", "mysql_password") or + die("Could not connect: " . mysql_error()); +mysql_select_db("mydb"); - $result = mysql_query("SELECT id, name FROM mytable"); +$result = mysql_query("SELECT id, name FROM mytable"); - while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { - printf ("ID: %s Name: %s", $row[0], $row["name"]); - } +while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { + printf ("ID: %s Name: %s", $row[0], $row["name"]); +} - mysql_free_result($result); +mysql_free_result($result); ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-fetch-assoc.xml diff -u phpdoc/en/reference/mysql/functions/mysql-fetch-assoc.xml:1.8 phpdoc/en/reference/mysql/functions/mysql-fetch-assoc.xml:1.9 --- phpdoc/en/reference/mysql/functions/mysql-fetch-assoc.xml:1.8 Wed Jul 9 11:07:29 2003 +++ phpdoc/en/reference/mysql/functions/mysql-fetch-assoc.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.45 --> <refentry id="function.mysql-fetch-assoc"> <refnamediv> @@ -49,45 +49,45 @@ <![CDATA[ <?php - $conn = mysql_connect("localhost", "mysql_user", "mysql_password"); - - if (!$conn) { - echo "Unable to connect to DB: " . mysql_error(); - exit; - } - - if (!mysql_select_db("mydbname")) { - echo "Unable to select mydbname: " . mysql_error(); - exit; - } - - $sql = "SELECT id as userid, fullname, userstatus - FROM sometable - WHERE userstatus = 1"; - - $result = mysql_query($sql); - - if (!$result) { - echo "Could not successfully run query ($sql) from DB: " . mysql_error(); - exit; - } +$conn = mysql_connect("localhost", "mysql_user", "mysql_password"); + +if (!$conn) { + echo "Unable to connect to DB: " . mysql_error(); + exit; +} - if (mysql_num_rows($result) == 0) { - echo "No rows found, nothing to print so am exiting"; - exit; - } - - // While a row of data exists, put that row in $row as an associative array - // Note: If you're expecting just one row, no need to use a loop - // Note: If you put extract($row); inside the following loop, you'll - // then create $userid, $fullname, and $userstatus - while ($row = mysql_fetch_assoc($result)) { - echo $row["userid"]; - echo $row["fullname"]; - echo $row["userstatus"]; - } - - mysql_free_result($result); +if (!mysql_select_db("mydbname")) { + echo "Unable to select mydbname: " . mysql_error(); + exit; +} + +$sql = "SELECT id as userid, fullname, userstatus + FROM sometable + WHERE userstatus = 1"; + +$result = mysql_query($sql); + +if (!$result) { + echo "Could not successfully run query ($sql) from DB: " . mysql_error(); + exit; +} + +if (mysql_num_rows($result) == 0) { + echo "No rows found, nothing to print so am exiting"; + exit; +} + +// While a row of data exists, put that row in $row as an associative array +// Note: If you're expecting just one row, no need to use a loop +// Note: If you put extract($row); inside the following loop, you'll +// then create $userid, $fullname, and $userstatus +while ($row = mysql_fetch_assoc($result)) { + echo $row["userid"]; + echo $row["fullname"]; + echo $row["userstatus"]; +} + +mysql_free_result($result); ?> ]]> Index: phpdoc/en/reference/mysql/functions/mysql-get-client-info.xml diff -u phpdoc/en/reference/mysql/functions/mysql-get-client-info.xml:1.5 phpdoc/en/reference/mysql/functions/mysql-get-client-info.xml:1.6 --- phpdoc/en/reference/mysql/functions/mysql-get-client-info.xml:1.5 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-get-client-info.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.62 --> <refentry id="function.mysql-get-client-info"> <refnamediv> @@ -22,7 +22,7 @@ <programlisting role="php"> <![CDATA[ <?php - printf("MySQL client info: %s\n", mysql_get_client_info()); +printf("MySQL client info: %s\n", mysql_get_client_info()); ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-get-host-info.xml diff -u phpdoc/en/reference/mysql/functions/mysql-get-host-info.xml:1.7 phpdoc/en/reference/mysql/functions/mysql-get-host-info.xml:1.8 --- phpdoc/en/reference/mysql/functions/mysql-get-host-info.xml:1.7 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-get-host-info.xml Mon Jan 5 08:03:26 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.62 --> <refentry id="function.mysql-get-host-info"> <refnamediv> @@ -25,9 +25,9 @@ <programlisting role="php"> <![CDATA[ <?php - mysql_connect("localhost", "mysql_user", "mysql_password") or - die("Could not connect: " . mysql_error()); - printf("MySQL host info: %s\n", mysql_get_host_info()); +mysql_connect("localhost", "mysql_user", "mysql_password") + or die("Could not connect: " . mysql_error()); +printf("MySQL host info: %s\n", mysql_get_host_info()); ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-get-proto-info.xml diff -u phpdoc/en/reference/mysql/functions/mysql-get-proto-info.xml:1.8 phpdoc/en/reference/mysql/functions/mysql-get-proto-info.xml:1.9 --- phpdoc/en/reference/mysql/functions/mysql-get-proto-info.xml:1.8 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-get-proto-info.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.62 --> <refentry id="function.mysql-get-proto-info"> <refnamediv> @@ -25,9 +25,9 @@ <programlisting role="php"> <![CDATA[ <?php - mysql_connect("localhost", "mysql_user", "mysql_password") or - die("Could not connect: " . mysql_error()); - printf("MySQL protocol version: %s\n", mysql_get_proto_info()); +mysql_connect("localhost", "mysql_user", "mysql_password") + or die("Could not connect: " . mysql_error()); +printf("MySQL protocol version: %s\n", mysql_get_proto_info()); ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-get-server-info.xml diff -u phpdoc/en/reference/mysql/functions/mysql-get-server-info.xml:1.7 phpdoc/en/reference/mysql/functions/mysql-get-server-info.xml:1.8 --- phpdoc/en/reference/mysql/functions/mysql-get-server-info.xml:1.7 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-get-server-info.xml Mon Jan 5 08:03:26 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.96 --> <refentry id="function.mysql-get-server-info"> <refnamediv> @@ -25,9 +25,9 @@ <programlisting role="php"> <![CDATA[ <?php - mysql_connect("localhost", "mysql_user", "mysql_password") or - die("Could not connect: " . mysql_error()); - printf("MySQL server version: %s\n", mysql_get_server_info()); +mysql_connect("localhost", "mysql_user", "mysql_password") + or die("Could not connect: " . mysql_error()); +printf("MySQL server version: %s\n", mysql_get_server_info()); ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-insert-id.xml diff -u phpdoc/en/reference/mysql/functions/mysql-insert-id.xml:1.8 phpdoc/en/reference/mysql/functions/mysql-insert-id.xml:1.9 --- phpdoc/en/reference/mysql/functions/mysql-insert-id.xml:1.8 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-insert-id.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-insert-id"> <refnamediv> @@ -56,12 +56,12 @@ <programlisting role="php"> <![CDATA[ <?php - mysql_connect("localhost", "mysql_user", "mysql_password") or - die("Could not connect: " . mysql_error()); - mysql_select_db("mydb"); +mysql_connect("localhost", "mysql_user", "mysql_password") + or die("Could not connect: " . mysql_error()); +mysql_select_db("mydb"); - mysql_query("INSERT INTO mytable (product) values ('kossu')"); - printf("Last inserted record has id %d\n", mysql_insert_id()); +mysql_query("INSERT INTO mytable (product) values ('kossu')"); +printf("Last inserted record has id %d\n", mysql_insert_id()); ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-list-tables.xml diff -u phpdoc/en/reference/mysql/functions/mysql-list-tables.xml:1.8 phpdoc/en/reference/mysql/functions/mysql-list-tables.xml:1.9 --- phpdoc/en/reference/mysql/functions/mysql-list-tables.xml:1.8 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-list-tables.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-list-tables"> <refnamediv> @@ -47,26 +47,26 @@ <programlisting role="php"> <![CDATA[ <?php - $dbname = 'mysql_dbname'; +$dbname = 'mysql_dbname'; - if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) { - echo 'Could not connect to mysql'; - exit; - } - - $result = mysql_list_tables($dbname); - - if (!$result) { - echo "DB Error, could not list tables\n"; - echo 'MySQL Error: ' . mysql_error(); - exit; - } - - while ($row = mysql_fetch_row($result)) { - echo "Table: $row[0]\n"; - } +if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) { + echo 'Could not connect to mysql'; + exit; +} - mysql_free_result($result); +$result = mysql_list_tables($dbname); + +if (!$result) { + echo "DB Error, could not list tables\n"; + echo 'MySQL Error: ' . mysql_error(); + exit; +} + +while ($row = mysql_fetch_row($result)) { + echo "Table: $row[0]\n"; +} + +mysql_free_result($result); ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-query.xml diff -u phpdoc/en/reference/mysql/functions/mysql-query.xml:1.8 phpdoc/en/reference/mysql/functions/mysql-query.xml:1.9 --- phpdoc/en/reference/mysql/functions/mysql-query.xml:1.8 Tue Sep 30 04:33:38 2003 +++ phpdoc/en/reference/mysql/functions/mysql-query.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.62 --> <refentry id="function.mysql-query"> <refnamediv> @@ -46,7 +46,7 @@ <title><function>mysql_query</function> example</title> <programlisting role="php"> <![CDATA[ -<php +<?php $result = mysql_query("SELECT * WHERE 1=1") or die("Invalid query: " . mysql_error()); ?> Index: phpdoc/en/reference/mysql/functions/mysql-result.xml diff -u phpdoc/en/reference/mysql/functions/mysql-result.xml:1.5 phpdoc/en/reference/mysql/functions/mysql-result.xml:1.6 --- phpdoc/en/reference/mysql/functions/mysql-result.xml:1.5 Thu Dec 18 12:45:43 2003 +++ phpdoc/en/reference/mysql/functions/mysql-result.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-result"> <refnamediv> @@ -43,15 +43,15 @@ <programlisting role="php"> <![CDATA[ <?php - $link = mysql_connect("localhost", "mysql_user", "mysql_password") - or die("Could not connect: " . mysql_error()); - - $result = mysql_query("SELECT name FROM work.employee") - or die("Could not query:" . mysql_error()); - - echo mysql_result($result, 2); // outputs third employee's name - - mysql_close($link); +$link = mysql_connect("localhost", "mysql_user", "mysql_password") + or die("Could not connect: " . mysql_error()); + +$result = mysql_query("SELECT name FROM work.employee") + or die("Could not query:" . mysql_error()); + +echo mysql_result($result, 2); // outputs third employee's name + +mysql_close($link); ?> ]]> </programlisting> Index: phpdoc/en/reference/mysql/functions/mysql-select-db.xml diff -u phpdoc/en/reference/mysql/functions/mysql-select-db.xml:1.5 phpdoc/en/reference/mysql/functions/mysql-select-db.xml:1.6 --- phpdoc/en/reference/mysql/functions/mysql-select-db.xml:1.5 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-select-db.xml Mon Jan 5 08:03:26 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-select-db"> <refnamediv> @@ -37,11 +37,11 @@ <![CDATA[ <?php -$lnk = mysql_connect('localhost', 'mysql_user', 'mysql_password') - or die('Not connected : ' . mysql_error()); +$link = mysql_connect('localhost', 'mysql_user', 'mysql_password') + or die('Not connected : ' . mysql_error()); // make foo the current db -mysql_select_db('foo', $lnk) or die ('Can\'t use foo : ' . mysql_error()); +mysql_select_db('foo', $link) or die ('Can\'t use foo : ' . mysql_error()); ?> ]]> Index: phpdoc/en/reference/mysql/functions/mysql-tablename.xml diff -u phpdoc/en/reference/mysql/functions/mysql-tablename.xml:1.7 phpdoc/en/reference/mysql/functions/mysql-tablename.xml:1.8 --- phpdoc/en/reference/mysql/functions/mysql-tablename.xml:1.7 Mon Dec 15 11:52:07 2003 +++ phpdoc/en/reference/mysql/functions/mysql-tablename.xml Mon Jan 5 08:03:26 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-tablename"> <refnamediv> @@ -27,13 +27,13 @@ <programlisting role="php"> <![CDATA[ <?php - mysql_connect("localhost", "mysql_user", "mysql_password"); - $result = mysql_list_tables("mydb"); +mysql_connect("localhost", "mysql_user", "mysql_password"); +$result = mysql_list_tables("mydb"); - for ($i = 0; $i < mysql_num_rows($result); $i++) - printf("Table: %s\n", mysql_tablename($result, $i)); +for ($i = 0; $i < mysql_num_rows($result); $i++) + printf("Table: %s\n", mysql_tablename($result, $i)); - mysql_free_result($result); +mysql_free_result($result); ?> ]]> </programlisting>
« previous php.doc (#969357942) next »