I have the following lines Of code for a database connection, however I would just want to use my include(“config.php”) Instead of this long line of code, how would i go about doing that
try {
$dbh = new PDO('mysql:host=localhost;dbname=lms;charset=UTF-8', 'root', 'password');
}
catch (PDOException $e) {
die('unable to connect to database ' . $e->getMessage());
}
// create LM object, pass in PDO connection
$lm = new lazy_mofo($dbh);
Just make a config.php file, for example consider this file is stored in web root (
/var/www/), then the contents of the config.php are like this:then in your other PHP scripts use the
includefunction:Now in your PHP scripts you can access the
$lmobject and$dbhobject.