• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 13. Serving from SQL > Connecting to a Database

Connecting to a Database

We exclusively write PHP code in this chapter (although one of the PHP commands we learn can take MySQL code as a parameter). PHP has several functions that allow a script to connect to a MySQL server, so we must have access to one before we can play with this code. In addition to connecting to the MySQL database via a series of functions, PHP also has a collection of functions that act on the returned data. The results of queries are stored by PHP as variables, so once the query is actually collected, it is quick to go through. Starting with the code in Chapter 10, we have to replace only the constructor of the Question class. Then our PHP code will be serving questions out of a database.

Connecting to a Server

To use PHP to interface with a MySQL database, the first thing we have to do is to connect to the server that hosts that database. The standard command used to connect to a server is


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint