| Viewed 108 times

How to open a connection to MySQL


I need a simple PHP code to open a connection to MySQL

1 Answer
Mohammad Qandeel
Answered
5

I`ll show you how to connect to MySQL using MySQLi Object-Oriented

<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

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

you need to replace MySql Username and MySql Password with your data

 


Related Questions