Database Reference
In-Depth Information
Figure 15.6
Result of testing connection to MySQL.
Copy the above file into the Apache root directory, which in this installation will be:
c:\indigoperl\apache\htdocs
Once it is there rename it to the following:
test.php
You can now view this in a browser, which will need to be pointed at:
http://localhost/test.php
You should see a webpage with the words It works on it, and nothing else. If you see the
PHP code and the previous tests worked, then you may not be looking at the file through
the webserver, or you may have incorrectly named the file.
Inside a PHP document, all HTML tags are processed as normal, but anything sur-
rounded by <?PHP … ?> is classed as PHP code and passed to the PHP server. The print
command simply outputs the string that you provide. All PHP commands are terminated
with a semicolon.
Accessing MySQL
MySQL is accessed in PHP through a series of functions whose results are stored in vari-
ables. You need to go through the following stages to access your data:
Connect to the database
Run the query
Deal with the results
Clear the results
Close the connection to the database.
Search WWH ::




Custom Search