Home » how to connect to phpmyadmin database in php?

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.

Read Also:  Laravel 6 SubQuery MySQL Tutorial with Examples

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)

<?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.

Read Also:  Woocommerce Get product image url from an image_id

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel Complex queries using Eloquent Query
  2. Read Also:  How to Convert XML to JSON in PHP?
  3. Read Also:  limit excerpt length in wordpress Example
  4. Read Also:  Multiple file Upload in Laravel 5.7 with validation
  5. Read Also:  Send WhatsAPP Message API using PHP Step By Step
  6. Read Also:  Laravel Debugging Raw SQL Queries result
  7. Read Also:  Laravel 6 eloquent Batch update multiple Jobs
  8. Read Also:  PHP MySQLi Database Connection
  9. Read Also:  laravel group by Eloquent Aggregate Query
  10. Read Also:  Laravel 6 eloquent Batch update multiple Jobs

Leave a Comment

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