Testing Time
Now that Apache, MySQL, and PHP are installed and configured, it is time to test your installation. Leave MySQL running. Apache should already be running, and the changes to the httpd.conf file are enough for Apache to know where to go when it receives .php files. Create a simple script to ensure that Apache and PHP are working together. Copy the following PHP test script to your WordPad or Notepad text editor:
<html>
<head>
<title>PHP_TESTER</title>
</head>
<body>
<?php
phpinfo();
?>
</body>
</html>
Save this file as phptester.php to the folder C:\apache2\Apache2\htdocs. Open your favorite Web browser and enter http://localhost/phptester.php. If this is working properly, you should see the details of the PHP installation you just performed.
Using PHP to Access MySQL via Apache
Now, connect to the MySQL database using PHP code. Copy the following into your favorite text editor:
<html>
<head>
<title>PHP_MySQL_Connection</title>
</head>
<body>
<!— start PHP insert and create MySQL connection details as variables —>
<?php
// database access variables
$Server = "localhost";
$Username = "root";
$Pass = "your-password-here";
$DataBaseName = "banking";
// connect PHP to MySQL
$Connection = mysql_connect ($Server, $Username, $Pass) or die ("Connection Denied");
// test the connection with a browser
if ($Connection) {
echo "<h3>Congratulations! You are ready to build dynamic database-driven Web sites</h3>";
} else {
echo "<h3>Back to the lab again*****Something went wrong</h3>";
}
// closing the connection is considered good form
mysql_close ($Connection);
// close the php
?>
</body>
</html>
And that is that. If you made it this far you now have the MySQL database, the Apache Server, and the PHP language working with each other. The Apache, PHP, and MySQL developers certainly have made high-quality products. Good luck with all your coding.