PHP How to Connect with MySQL Database Using PHP

Php for Beginners - How to create a Connection to MySQL Database Using PHP? how to make 3 step of make a connection string with MySQL database with PHP Programming languages? Web-based PHP programming language is a programming language that is much sought after by web designers and most popular in Indonesia. In addition to the performance and features of the new and advanced features – that is on a new course in PHP7 updates make PHP programmers increasingly. PHP Programming language especially in Indonesia is most often used in developing and making the application-based website.

The first lesson in a special beginners learn PHP tutorial on this occasion about how to make connection PHP to a MySQL database that may have been much discussed on the Internet. But here we are a little to distinguish the basic PHP tutorials. Where we will make a connection PHP to a MySQL database with a different wording, such as making a connection php mysql extension, mysqli extension, and PDO (PHP Data Objects).

Hear the words of the PDO is possible for unfamiliar with programming languages primarily PHP will sound familiar. What the heck is up with PDO (PHP Data Objects)? PDO is an abbreviation of PHP Data Objects and is the most consistent and most slender for connect data to the database server. PDO is a universal interface that is already provided by PHP itself and will make it easier for the developer to make a connection to the database. The use of the PDO in PHP application will greatly help the programmer if one day like to migrate from one database to another database with easy just have to change the way initial callings PDO and automatically be used for the new database.

PHP How to Connect with MySQL Database Using PHP

If you create a connection to a MySQL database with PHP using MySQL and MySQLi extension extension you have to modify the whole code if at any time you would like to use other database migration. Very troublesome for php programmers.

How To Enable PDO Extension ?

For the Actived PDO Extension on localhost or your server please open the file "php.ini", the location of the file is usually located in the php folder, /xampp/php/php.ini. You can open php.ini with any your favourite text editor. Enable extension = php_pdo_mysql.dll Please remove the sign (;) If using MySQL database. Do not forget to save again and restart Xampp Controll Panel. When you've finished everything is ready for use.

Making a connection MySQL database using PHP MySQL Extension

<php
$yourserver="localhost"; // Server name
$user="root"; // User Server
$pass=""; // Password Server
$db="test"; // Database name
$konek=mysql_connect($yourserver, $user, $pass);
if ($konek) {
mysql_select_db($db) or die ("Database not found");
echo "Connect success";
} else {
echo "connect failed";
}
?>

Making a connection MySQL Database using PHP MySQLi Extension

<php
$yourserver="localhost"; // Server name
$user="root"; // User Server
$pass=""; // Password Server
$db="test"; // Database name
$konek=new mysqli($yourserver, $user, $pass);
if ($konek) {
mysql_select_db($db) or die ("Database Not found");
echo "Connection Success";
} else {
echo "Connection Failed";
}
?>

Making a connection MySQL Database using PDO

<php
$yourserver="localhost"; // Server name
$user="root"; // User Server
$pass=""; // Password Server
$db="test"; // Database Name
$konek=new PDO('mysql:host=$yourserver;dbname=$db', '$user', '$pass');
?>

Try and ask any questions !