How to Connect to phpmyadmin Database in PHP

Connect phpmyadmin MySQL database in PHP with xampp. Here, i will teach you how to connect phpmyadmin database in php with xampp code.

First of all, you need to know about mysqli functions, which is used to connect phpmyadmin database in php with xampp.

In this post i will show you how to use mysqli_connect() for connect phpmyadmin database in php with xampp.

Syntax of MySQLi_connect()

The syntax of connect mysqli_connect() function, which is used to connect phpmyadmin database in php:

  • mysqli_connect :- PHP offers mysqli_connect() function to establish phpmyadmin database connection. And it take 5 argument and returns a MySQL link identifier on success or FALSE on failure.
  • Host :- The hostname that runs the database server If not specified, the default value will be localhost.
  • UserName Of mysql Database :- Username accessing the database If not specified, the default will be the name of the user who is the owner of the server process.
  • Password of mysql database :- The default value is defined by MySQL default password. In SQL secure mode, this parameter is ignored and a blank password is used.
  • New link :- If mysqli_connect () is called with other arguments, no new connection will be established. Instead, the identifier of the already open connection will be returned.
    • MYSQL_CLIENT_SSL – Use SSL encryption.
    • MYSQL_CLIENT_COMPRESS – Use Compression Protocol.
    • MYSQL_CLIENT_IGNORE_SPACE – Allow the location after the function names.
    • MYSQL_CLIENT_INTERACTIVE – Allow passive seconds of idle time before closing connection.

How to Connect to PHPMyAdmin Database in PHP

Use the below given php code to connect phpmyadmin database with xampp.

  • First of all, start xampp server. Then start apahce and mysql server.
  • Then open your browser and type localhost/phpmyadmin
  • After that, create new database and table
  • Then navigate to xampp/htdocs and create heree one file named mydb.php.
  • And open mydb.php file on any text editor.
  • Then add the below given code into mydb.php file.
  • Now open your browser and type localhost/mydb.php.

Let’s, add the following code in your mydb.php file for connecting a phpmyadmin database in php with xampp:


$hostName = "localhost";
$userName = "username";
$password = "password";

// Create connection
$conn = mysqli_connect($host, $username, $password);

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


Explaination of php program to connect mysql database:

The server name, database, username, and password and their respective values should correspond to your phpmyadmin connection.

The PHP function mysqli_connect(). It open a connection with the specified phpmyadmin database.

The “if statement.” is used to check whether the connection was established or not. If the phpmyadmin connection fails, it return the message Connection failed.

If the connection is successful, it displays “Connected successfully.”

At the last of php script, the phpmyadmin database connection also closes. If you want to close phpmyadmin database manually, use the mysqli_close function.


PHPmyadmin database connection in php with mysql in xampp code. Here you have learned how to connect phpmyadmin database in php with xampp code.

Recommended PHP Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published.