In connecting your database you have to set it properly with your localhost,username,and the password
I just make an example for you to easily understand ion how to connect your database from your program.
in a new file create a connection.php
then after you create copy the code below and change the servername, username and the password and try link this to your files.
- <?php
-
$servername = "localhost"; // this is the default
-
$username = "username"; // the default is root and use your username if you change it.
-
$password = "password"; // if your database has no password just leave it blank "";
-
-
try {
-
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
-
// set the PDO error mode to exception
-
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-
echo "Connected successfully";
-
}
-
catch(PDOException $e)
-
{
-
echo "Connection failed: " . $e->getMessage();
-
}
-
?>
-
this sample code is PDO, but you can also use the Object-Oriented , Procedural if want.
I hope it helps. :)