Make connection.php file and insert following code in it, include this file wherever you need database connection(i.e Model file)
<?php
try
{
$host=’localhost’;
$dbname=’YOUR_DATABASE_NAME’;
$user=’MYSQL_USERNAME’; //GENERALLY root FOR LOCALHOST
$pass=’MYSQL_PASSWORD’; //GENERALLY BLANK FOR LOCALHOST
$dbo=new PDO(“mysql:host=$host;dbname=$dbname”,$user,$pass);
$dbo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo “database config2 connection error!”;
file_put_contents(‘config2.txt’,$e->getMEssage(),FILE_APPEND);
}
?>