Mysql PHP

PHP PDO Database Connection

PHP PDO Database Connection

Hi, In this tutorial we are going to see how to connect the database in PDO using php. Now a days Mysql are getting depricated, so the developers need to learn  Mysqli or PDO.
Here we can see few stuffs in PDO.

How to connect database:

 

Let us assume we have table called tbl_users and has the following fields,

id,
name,
email_id,
contact_no

 

Select Operations :

The following query will select all the records from the table.

 Or When trying in function

 



Insert Operation :

Here we are using binding statement to insert the data into database, By using this we can avoid the mysql injections.
The way of binding data is :foo without any quotes. instead of :foo you can use ? also,

 Select Single Row

The following query will select single row based in id.

Updating Row

The below query will update the row based in ID.

Deleting Row

The below query will delete the row based in ID.

Thanks for reading this article, If you like this please don’t forget to share and comment.