Although PHP can read and write files on a web server, in practice it is much more useful to use a database for data storage and retrieval. MySQL is a popular open source relational database management system (DBMS) that is widely used by web applications. This lesson covers how to access a MySQL database using PHP’s MySQL extensions.

Learning Objectives

  • Connect to a database using PHP
  • Use a prepared statement to execute queries using PHP

How to Complete this Lesson

Complete the following learning activities: (3.5–4.5 hours total)

  1. Complete the following W3Schools tutorials (these have multiple parts):
    • PHP Advanced (20–30 minutes)
    • PHP MySQL Database (15–20 minutes)
      • Focus on the object-oriented MySQLi syntax, which will be used elsewhere in this course, and ignore the other examples
  2. Optional: Complete W3Schools’s PHP Quiz to test your understanding of PHP (10–15 minutes)
  3. Attend the class meeting (60 minutes)
  4. Complete the practice exercises (45–90 minutes)
  5. Work on the web development programming exercise (PEX) (60 minutes)
    • Pass the automated tests for the website