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.

MySQL Connection Using (MySQLi Object Oriented)

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 = "Paka@98256";

// 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 = "Paka@98256";

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.

Leave a Comment