how to connect to phpmyadmin database in php?

Today, We want to share with you How to Connect MySQL Database with PHP Website?.In this post we will show you database connection in php with mysql in xampp code, hear for php database connection example program we will give you demo and example for implement.In this post, we will learn about PHP MySQL Connect Database Script with an example.

PHP MySQL Connect to database

hello gyu’s lets start to learn all about MySQL Database Connecting step by step using PHP Example.

Read Also:  How to delete tables from a database in mysql phpMyAdmin?

MySQL Connection Using (MySQLi Object Oriented)

<?php
$host_name = "localhost";
$db_user_name = "root";
$db_password = "[email protected]";

// Create connection
$conn = new mysqli($host_name, $db_user_name, $db_password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?> 

MySQL Connection Using (MySQLi Procedural)

$host_name = "localhost";
$db_user_name = "root";
$db_password = "[email protected]";

// Create connection
$conn = mysqli_connect($host_name, $db_user_name, $db_password);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Good Luck, Connected successfully";

MySQL Connection Using PDO

$host_name = "localhost";
$db_user_name = "root";
$db_password = "[email protected]";

try {
    $conn = new PDO("mysql:host=$host_name;dbname=myDB", $db_user_name, $db_password);

    	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    	echo "Good Luck, Connected successfully";
    }
catch(PDOException $e)
    {
    	echo "Sorry, Connection failed: " . $e->getMessage();
    }

I hope you get an idea about database connection in php with mysqli example.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.