September 2017
Intermediate to advanced
244 pages
6h 44m
English
Here is the code of the DB class in blog/core/DB.php:
<?phpclass DB { function connect($db) { try { $conn = new PDO("mysql:host={$db['host']};dbname=blog", $db['username'], $db['password']); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $conn; } catch (PDOException $exception) { exit($exception->getMessage()); } }}
This class is related to the database. Right now, we have a constructor that is actually connecting to the database using PDO and $db arrays defined in blog/config.php. However, we will add more in this class later.
You can see we are using a PDO object here: PDO (PHP Data Objects). It is used to interact with databases and is a recommended one because it ...
Read now
Unlock full access