How To Connect to a MySQL Database Using PHP With The mysqli Function

Here is an example of PHP code to connect to a MySQL database:

$servername = "server_name";
$username = "username";
$password = "password";
$dbname = "database_name";

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

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

Replace server_name, username, password, and database_name with the appropriate values for your database.

Leave a Reply

Proudly powered by WordPress | Theme: Code Blog by Crimson Themes.