link a database with php code example
Example 1: db connection in php
Just include this Temlate in other file using PHP Include/Require Keywords
And Make Connection In One Shot :)
<?php
$server = "localhost";
$username = "root";
$password = "";
$database = "test";
$con = mysqLi_connect($server, $username, $password, $database);
if(!$con){
die ("Connection Terminated! by Die() function". mysqLi_connect_error());
}
else {
echo "Connection Succefully Happened! <br>";
}
?>
Example 2: using mysql database with php
<?php
$servername = "localhost";
$username = "yourusername";
$password = "yourpassword";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>