Web pages on the Ïã¸ÛÁùºÏ²Ê Web server which use PHP can access databases on the MySQL server. Full details of the PHP MySQL API (Application Program Interface) can be found in the on-line .
Pages using PHP/MySQL can also be created using Dreamweaver MX.
A page such as the following example should be saved in a file with a .php extension. Note that PHP pages only work in the main , and not in users' personal html.pub web space. This example displays the names and ages in table people in database ucabwww, where the person's age is over 18.
<html>
<head> <title>PHP/MySQL example</title> </head>
<body bgcolor="white">
<table border="1"> <tr><th>Name</th><th>Age</th></tr>
<?php $host="mysql-server.ucl.ac.uk"; $user="ucabwww"; $password="secret";
# Connect to MySQL server $conn = mysql_connect($host,$user,$password) Â Â or die(mysql_error());
# Select the database mysql_select_db("ucabwww", $conn) Â Â or die(mysql_error());
# Send SQL query $sql = "SELECT * FROM people WHERE age > 18 ORDER BY name"; $result = mysql_query($sql) Â Â or die(mysql_error());
# Fetch table rows, one by one, and display as HTML table rows while ($row = mysql_fetch_assoc($result)) { Â Â echo "<tr><td>", $row['Name'], "</td><td>", $row['Age'], Â Â Â Â Â "</td></tr>\n"; } ?>
</table> </body> </html>