Knowledge7

The Linux and Mobile Solution Provider

  • About
  • Training
  • Services
  • Clients
  • In the news
  • Blog
  • Contact Us
You are here: Home / Topic / Accessing MySQL with PHP

Accessing MySQL with PHP

This topic is part of our Web Development with PHP and MySQL training

PHP can access MySQL databases using a number of libraries. Two of them are mysqli and PDO, both part of standard PHP. mysqli provides functions to manipulate data in a MySQL database. PDO, as stated on the PHP website:

The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. Note that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.

PDO provides a data-access abstraction layer, which means that, regardless of which database you’re using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn’t rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility.

PDO ships with PHP 5.1

The work to do is to modify the web application being written to make it save orders to a MySQL database instead of in a text file. The first thing to do is to decide upon a schema (i.e. tables and columns). The application will use PDO.

Prepared statements

In order to increase performance and security, it is advisable to use prepared statements when this is possible.

The work to do is to add to the web application a second report. This report should give, for each customer, the amount of phones bought and the cost. In case, the amount is more than 20, that customer should get 20% for this phone. If the number of phones is between 10 and 19, the customer should get 10% off.

This topic is part of our Web Development with PHP and MySQL training

Our forthcoming training courses

  • No training courses are scheduled.

Looking for something?

Want to know more?

Get our newsletter

Discover the latest news, tips and tricks on Linux, the Web and Mobile technologies every week for FREE

This work is licensed by Knowledge7 under an Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license.