13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

11<br />

Accessing Your <strong>MySQL</strong> Database<br />

from the <strong>Web</strong> with <strong>PHP</strong><br />

PREVIOUSLY, IN OUR WORK WITH <strong>PHP</strong>, WE used a flat file to store <strong>and</strong> retrieve data.<br />

When we looked at this file in Chapter 2,“Storing <strong>and</strong> Retrieving Data,” we mentioned<br />

that relational database systems make a lot of these storage <strong>and</strong> retrieval tasks easier, safer,<br />

<strong>and</strong> more efficient in a web application. Now, having worked with <strong>MySQL</strong> to create a<br />

database, we can begin connecting this database to a web-based front end.<br />

In this chapter, we explain how to access the Book-O-Rama database from the <strong>Web</strong><br />

using <strong>PHP</strong>.You learn how to read from <strong>and</strong> write to the database <strong>and</strong> how to filter<br />

potentially troublesome input data.<br />

Key topics covered in this chapter include<br />

n How web database architectures work<br />

n Querying a database from the <strong>Web</strong> using the basic steps<br />

n Setting up a connection<br />

n Getting information about available databases<br />

n Choosing a database to use<br />

n Querying the database<br />

n Retrieving the query results<br />

n Disconnecting from the database<br />

n Putting new information in the database<br />

n Using prepared statements<br />

n Using other <strong>PHP</strong>-database interfaces<br />

n Using a generic database interface: PEAR MDB2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!