Section 5.3 Accessing a MySQL Database with PHP
Learning Objectives
After you have completed this section, you should be able to
- access MySQL database with PHP.
- use PHP and MySQL together to implement authentications and secure transactions in e-commerce systems.
Activities
- Carefully read the learning objectives.
- Find and study some PHP scripts on the web.
- Find some examples of websites that use PHP with MySQL and write a summary of the function and implementation of each website.
- Watch the related sections of the presentation for Chapter 19;
- Read section 19.9 of Chapter 19.
- See the list of functions at https://www.php.net/manual/en/ref.mysql.php
- Find answers to the study questions below.
- Write a web page that uses passwords stored in a file to authenticate a web user.
- Design a web page using PHP that can serve as an interface to MySQL databases. You should document your design in detail because this exercise will be expanded in the Assignment 2 project.
Study Questions
- How do web database architectures work?
- What are the basic steps in querying a database from the Web?
- How do you connect a database from the Web?
- How do you check and filter input data from a web user?
- How do you get information about available databases in PHP?
- How do you choose a database in PHP?
- How do you query a database?
- How do you retrieve the query result?
- How do you disconnect from the database?
- How do you add new information into the database?
- How do you make your database secure?
- How do you free up resources?
- How do you create and delete a database in PHP?
- In addition to MySQL, what other databases does PHP provide interfaces to?
Implementing Authentication with PHP and MySQL
- Why do you need to authenticate web users?
- How do you identify visitors to your website?
- How can you implement access control in PHP without using MySQL?
- How can you implement access control in PHP with MySQL?
- How do you encrypt passwords in PHP?
- How do you protect multiple pages with access control?
- How does HTTP support authentication?
- How do you use basic authentication provided by HTTP in PHP?
- In PHP, how do you use basic authentication with Apache’s .htaccess files?
- What is mod_auth_mysql authentication? How do you use it?
Implementing Secure Transactions with PHP and MySQL
- What are secure transactions on the Web?
- What do we mean by providing secure transactions?
- How can secure transactions be provided on the Web?
- What mechanisms are ready for use to provide secure transactions on the Web?
- What is secure socket layer (SSL)?
- Where does SSL sit in the Internet protocol stack?
- How is an SSL connection established between a web browser and a web server?
- How is data sent over an SSL connection?
- How do you screen user input in PHP?
- How do you provide secure storage in PHP and MySQL?
- Where should you store credit card numbers at your website?
- How do you use encryption in PHP?
- How do you install PGP on your site?
- What can PGP be used to do? How is it used?
Summary
PHP and MySQL seem to be a perfect combination for website development. First of all, both systems are free for non-commercial uses, and secondly, they have high performance: speed, functionality, and scalability. Although there are many other systems you can use to develop your websites, PHP and MySQL are worth your close attention.