how to create a pdo php project with database connection code example
Example 1: connect php to mysql pdo
<?php
$pdo = new PDO('mysql:host=localhost;
dbname=the_name_of_your_databe,
'username',
'password'');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
?>
Example 2: 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>";
}
?>