Saturday, November 8, 2008

PHP Tutorial: how PHP Fits with MySQL

With the onset of PHP5, you need to take a few extra steps to convince PHP and MySQL to play well
with each other. Before your MySQL functions will be recognizable by PHP, make sure to enable MySQL
in your php.ini file, which we covered in Chapter 1.
You can use MySQL commands within PHP code almost as seamlessly as you do with HTML.
Numerous PHP functions work specifically with MySQL to make your life easier; you can find a comprehensive
list in Appendix C.
Some of the more commonly used functions are:
❑ mysql_connect ("hostname", "user", "pass"): Connects to the MySQL server.
❑ mysql_select_db("database name"): Equivalent to the MySQL command USE; makes the
selected database the active one.
❑ mysql_query("query"): Used to send any type of MySQL command to the server.
❑ mysql_fetch_rows("results variable from query"): Used to return a row of the entire
results of a database query.
❑ mysql_fetch_array("results variable from query"): Used to return several rows of
the entire results of a database query.
❑ mysql_error(): Shows the error message that has been returned directly from the MySQL server

No comments: