Section 0: Module Objectives or Competencies
Course Objective or Competency |
---|
The student will be able to write basic PHP applications in order to connect to and manipulate a database using PHP. |
The student will be able to utilize a wide range of features available in MySQL. |
Section 1: Overview
These notes are derived, in part, from this chapter.
We have two powerful tools at our disposal: the PHP scripting language and the MySQL database engine.
It’s important to understand how these will fit together.
-
The whole idea of a database-driven web site is that the
contents of the site reside in a database, and that content
is pulled from the database dynamically to create web pages
for people to view with a regular web browser.
- At one end of the system you have a visitor to your site who uses a web browser to request a page, and expects to receive a standard HTML document in return.
- At the other end you have the content of your site, which sits in one or more tables in a MySQL database that understands only how to respond to SQL queries (commands).
-
As the image above shows, the PHP scripting language is the
go-between that speaks both languages.
- It processes the page request and fetches the data from the MySQL database, then spits it out dynamically as the nicely formatted HTML page that the browser expects.
Section 2: Recap
Here is a recap of what happens when a person visits a page on a database-driven web site:
- The visitor’s web browser requests the web page using a standard URL.
- The web server software recognizes that the requested file is a PHP script, so the server fires up the PHP interpreter to execute the code contained in the file.
- Certain PHP commands connect to the MySQL database and request the content that belongs in the web page.
- The MySQL database responds by sending the requested content to the PHP script.
- The PHP script stores the content into one or more PHP variables, then uses echo statements to output the content as part of the web page.
- The PHP interpreter finishes up by handing a copy of the HTML it has created to the web server.
- The web server sends the HTML to the web browser as it would a plain HTML file, except that instead of coming directly from an HTML file, the page is the output provided by the PHP interpreter.