PHP MySQL Tutorial: PHP is the most popular scripting language on the web, which is used to make
dynamic websites. One of the feature of PHP is that it can work with Database Management Systems to access and manipulate data inside a database. It simply means that you can create a fully functional website connected to a database by combining PHP with a Database Management System.
In this tutorial, we will learn about how we can use a Database Management System (
DBMS) with PHP.
The DBMS we are using is
'MySql' often pronounced as
'Mysequel'. Now, what is mysql?,
it is a very popular and one of the first Relational Database Management System (
RDBMS) that uses Structured Query Language (
As Mysql is free, just like PHP, you can download it from
http://www.mysql.com. But nowadays, if you have a PHP server installed like
LAMP, etc. you don't need to download it as 'MySql' comes pre-installed with these servers. We will learn more about what is MySQL and what are its features which made it the most popular DBMS. In this tutorial, we will learn MySQL and the working of PHP and MySQL together.
PHP has many in-built functions specially for manipulating the database. The functions can easily connect the website built in PHP and the MySQL database and after that can also do various operations on the database within the website. These features and functions of PHP make it compatible to use in combination with MySQL.
Before learning about how PHP and MySQL interact together, look at the basics of SQL below, it will help you in this MySQL tutorial:
As MySQL is a Relational DBMS, it stores data in the form tables in the database as any other relational database.
In a table, the data is divided in the form of
A table stores data about any particular event/object/person. The rows in the table represent different
records that are inherently connected such as in the example shown below different rows represent a similar type of information but for different persons. The columns in the table represent different fields to enter information about.
In the example below fields like
last_name, etc. are the columns.
The whole structure of a MySQL table that contains a person's information may look like this:
MySQL databases use Structured Query language (SQL) to create and manage the database, so we should have a basic knowledge of SQL also to be able to use all the features of MySQL. SQL is a very powerful language for managing a database. If you know SQL then you can manually enter a query in the database and use it even if it is not included in the MySQL interface.
Throughout this MySQL tutorial, we will learn about PHP and MySQL interaction and also how to interact with MySQL
using PHP Data Object (
PDO). There are two types of extensions in PHP, MySQLi, and PDO.
There was one more, known as MySQL which was depreciated in PHP 7. The MySQLi only supports MySQL databse but PDO has an advantage that it supports 12 different database types. Well, MySQL has its other advantages like asynchronous queries, proper database closing methods, etc. also it is the popular one.
Connecting to MySQL Database – This MySQL tutorial will show you how to connect the web application with the database using MySQLi and PDO.
Fetching data from the database – How you can fetch data from the database and then use it in your web application.
Inserting Data into database – How to insert data in the database right from the web application using MySQLi or PDO.
Updating Data – You can also update the data in the database if there is some correction you want to do or if there is some update about the data.
Delete Data – You can also delete data from the database by using predefined functions of PHP extensions.
Lets jump into the learning part click on the next button to start your tutorial. We ensure you that you will get all your answers related to database connections in this MySQL tutorial but if there is something we have missed, then give us your feedback and send your query to our e-mail address.
We have laerned mysql