From 077741678fd7ba26db9b333bddca1ca367cfef39 Mon Sep 17 00:00:00 2001 From: Damien Seguy Date: Mon, 28 May 2001 08:37:11 +0000 Subject: [PATCH] Turned ?> -> ?> git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@48749 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/mysql.xml | 59 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/functions/mysql.xml b/functions/mysql.xml index 9bffbdd28c..bedbbaf05e 100644 --- a/functions/mysql.xml +++ b/functions/mysql.xml @@ -24,7 +24,40 @@ Documentation for MySQL can be found at &url.mysql.docs;. + + This simple example shows how to connect, execute a query, print + resulting rows and disconnect from MySQL Database. + + MySQL extension overview example + +<?php + $link = mysql_connect("mysql_host", "mysql_login", "mysql_password") + or die ("Could not connect"); + print ("Connected successfully"); + mysql_select_db ("my_database") + or die ("Could not select database"); + + $query = "SELECT * FROM my_table"; + $result = mysql_query ($query) + or die ("Query failed"); + // printing HTML result + + print "\n"; + while($line = mysql_fetch_array($result, MYSQL_){ + print "\t\n"; + while(list($col_name, $col_value) = each($line)){ + print "\t\t\n"; + } + print "\t\n"; + } + print "
$col_value
\n"; + + mysql_close($link); +?> +
+
+
@@ -176,7 +209,7 @@ or die ("Could not connect"); print ("Connected successfully"); mysql_close ($link); -?> +?> @@ -311,7 +344,7 @@ } else { printf ("Error creating database: %s\n", mysql_error ()); } -?> +?> @@ -380,7 +413,7 @@ } mysql_free_result ($result); -?> +?> @@ -562,7 +595,7 @@ mysql_select_db("nonexistentdb"); echo mysql_errno().": ".mysql_error()."<BR>"; $conn = mysql_query("SELECT * FROM nonexistenttable"); echo mysql_errno().": ".mysql_error()."<BR>"; -?> +?> @@ -611,7 +644,7 @@ mysql_select_db("nonexistentdb"); echo mysql_errno().": ".mysql_error()."<BR>"; $conn = mysql_query("SELECT * FROM nonexistenttable"); echo mysql_errno().": ".mysql_error()."<BR>"; -?> +?> @@ -718,7 +751,7 @@ while ($row = mysql_fetch_array ($result)) { echo "fullname: ".$row[1]."<br>\n"; } mysql_free_result ($result); -?> +?> @@ -777,7 +810,7 @@ while ($row = mysql_fetch_assoc ($result)) { echo $row["fullname"]; } mysql_free_result ($result); -?> +?> @@ -910,7 +943,7 @@ zerofill: $meta->zerofill $i++; } mysql_free_result ($result); -?> +?> @@ -1003,7 +1036,7 @@ while ($row = mysql_fetch_object ($result)) { echo $row->fullname; } mysql_free_result ($result); -?> +?> @@ -1278,7 +1311,7 @@ while ($i < $fields) { } mysql_close(); -?> +?> @@ -1749,7 +1782,7 @@ echo "$num_rows Rows\n"; <?php $result = mysql_query ("SELECT * WHERE 1=1") or die ("Invalid query"); -?> +?> @@ -1764,7 +1797,7 @@ $result = mysql_query ("SELECT * WHERE 1=1") <?php $result = mysql_query ("SELECT my_col FROM my_tbl") or die ("Invalid query"); -?> +?> @@ -1972,7 +2005,7 @@ while ($i < mysql_num_rows ($result)) { echo $tb_names[$i] . "<BR>"; $i++; } -?> +?>