How to Connect MySql Database using PHP

How to Connect MySql Database using PHPHow to connect MySql database using PHP. PHP provides inbuilt functions to connect to MySql database using their extensions. In this post, I’ll explain how to connect MySql Database using  PHP.

In PHP, you can connect MySql database using following extensions.

1) MySql (Worked only if you are using PHP Version 5.4 or less than that)

2) MySqli (MySql Improved)

3) PDO (PHP Data Objects)

Mysql API extension is deprecated from PHP 5.4 and now this extension is removed from the current version of PHP. So it’s better to learn how to connect MySql database using MySqli and PDO .

PHP Traits

Late static binding in PHP

Advantage of using MySqli and PDO

Subscribe Our Tutorials

Get Latest Updates on Facebook

1. MySqli and PDO both supports parameterized query which is helpful in preventing an application from SQL injection .

2. Both supports object-oriented interface.

3. Accessing database through MySqli and PDO is faster than previously used MySql API extension.

Difference Between MySqli and PDO

Difference between MySqli and PDO

How to Connect MySql Database using PHP

To access MySql database in your code, you need to do following steps –

1. Open a connection.

2. Specify and Connect to the database.

3. Once connection is establish, query(Select/Insert/Update) the database.

4. Close the connection.

Connect MySql Database using PHP MySqli

 

Read detail post here –  How to connect MySql Database using PHP MySqli.

Connect MySql Database using PHP PDO

To prevent an application from SQL injection try to use the prepared statement.

Read detail post on connecting MySQL database using PDO.

How to connect MySql Database using PDO

PHP Online Video Tutorials

WebRewrite

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , , , . Bookmark the permalink.
  • robbyoconnor

    Actually unless you use prepared statements, you can still write code vulnerable to sql injection using mysqli and pdo. You MUST limit the character set to UTF-8.

    This tutorial is garbage and the author is a fraud who should not be teaching.