LV. MySQL Functions
These functions allow you to access MySQL database servers. In
order to have these functions available, you must compile php
with MySQL support by using the
--with-mysql option. If you
use this option without specifying the path to MySQL, php will
use the built-in MySQL client libraries. Users who run other
applications that use MySQL (for example, running php3 and php4
as concurrent apache modules, or auth-mysql) should always
specify the path to MySQL:
--with-mysql=/path/to/mysql.
This will force php to use the client libraries installed by
MySQL, avoiding any conflicts.
More information about MySQL can be found at http://www.mysql.com/.
Documentation for MySQL can be found at http://www.mysql.com/documentation/.
This simple example shows how to connect, execute a query, print
resulting rows and disconnect from MySQL Database.
Example 1. 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 "<table>\n";
while ($line = mysql_fetch_array($result)) {
print "\t<tr>\n";
while(list($col_name, $col_value) = each($line)) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";
mysql_close($link);
?>
|
|