Exemplo n.º 1
0
 /**
  * @description connect the database
  * @param null
  * @return an object of the PDO
  */
 public function connect()
 {
     $config = new DbConfig();
     try {
         $pdo = new PDO($config->getDBNameHost(), $config->getDBUsr(), $config->getDBPwd());
         // set attributes of the PDO
         $pdo->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
         $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
         $pdo->query("set names utf8");
         echo date("Y-m-d h:i:s") . " :connect to database successfully...<br>";
         return $pdo;
     } catch (PDOException $e) {
         echo date("Y-m-d h:i:s") . " :Could not connect to the database:<br>.{$e}";
     }
 }