There was a problem loading the comments.

How do I connect to my MySQL database?

Support Portal  »  Knowledgebase  »  Viewing Article

  Print
A simple PHP script to open a connection to a database. Save this as db_connect.php and then whenever you want to access the database, just add include 'db_connect.php' to the top of a PHP script and the database can be queried using standard SQL commands.

<?php

$servername = "ServerName";
$username = "username";
$password = "password";
$dbname = "database name";

// Create the connection to the database with the above credentials
$conn = new mysqli($servername, $username, $password, $dbname);

// Check the status of the connection and return a message if failed or connected
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";

?>

Share via
Did you find this article useful?  

Related Articles

© Eco Web Hosting