Home / Web Development Technologies / MYSQL PDO Connection

MYSQL PDO Connection

MYSQL PDO Connection

MYSQL PDO Connection: PDO tutorial for MSYQL Developer

what is PDO?
“PHP Data Objects (PDO) is a database abstraction layer giving a uniform technique for access to different databases.”

Numerous PHP developers figured out how to get to databases by utilizing either the MySQL or MySQLi expansions. As of PHP 5.1, there’s a superior way. PHP Data Objects (PDO) give strategies to prepared statements and working with objects that will make you significantly more gainful!

MYSQL PDO Connection

Connecting MYSQL using old way:

<?php
$Con = mysql_connect(‘servername’, ‘username’, ‘userpassword’);
mysql_select_db(‘yourdb’, $Con);
?>

Connecting MYSQL using new way:
Create a new PDO object. PDO’s constructor takes 4 parameters, DSN, username, password, and an array of driver options.
A DSN is fundamentally a string of options that advise PDO which driver to utilize, and the connection points of interest. You can look up every one of the options here PDO MYSQL DSN.

<?php
$db = new PDO(‘mysql:host=localhost;dbname=testdb;charset=utf8’, ‘username’, ‘password’);
?>

Note: On the off chance that you get an error about character sets, ensure you add the charset parameter to the DSN. Adding the charset to the DSN is essential for security reasons most cases you’ll see around forget it. So you have to include the DSN.

MYSQL PDO Connection: PDO tutorial for MSYQL Developer what is PDO? "PHP Data Objects (PDO) is a database abstraction layer giving a uniform technique for access to different databases." Numerous PHP developers figured out how to get to databases by utilizing either the MySQL or MySQLi expansions. As of PHP 5.1, there's a superior way. PHP Data Objects (PDO) give strategies to prepared statements and working with objects that will make you significantly more gainful! MYSQL PDO Connection Connecting MYSQL using old way: Connecting MYSQL using new way: Create a new PDO object. PDO's constructor takes 4 parameters, DSN, username,…

User Rating: 4.6 ( 1 votes)

Check Also

AngularJS and Laravel Blade

How to use AngularJS and Laravel Blade together

How to use AngularJS and Laravel Blade together In this article I will show you …

Ajax Pagination Using Laravel

How to Create an Ajax Pagination Using Laravel

In this article I will demonstrate one way to create an Ajax pagionation using Laravel …

Leave a Reply

Your email address will not be published. Required fields are marked *