* @return bool success
*/
public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) {
+ $driverstatus = $this->driver_installed();
+
+ if ($driverstatus !== true) {
+ throw new dml_exception('dbdriverproblem', $driverstatus);
+ }
+
$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
- try {
+ try{
$this->pdb = new PDO($this->get_dsn(), $this->dbuser, $this->dbpass, $this->get_pdooptions());
// generic PDO settings to match adodb's default; subclasses can change this in configure_dbconnection
$this->pdb->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
$this->configure_dbconnection();
return true;
} catch (PDOException $ex) {
+ throw new dml_connection_exception($ex->getMessage());
return false;
}
}
* @return mixed true if ok, string if something
*/
public function driver_installed() {
- if (!extension_loaded('pdo_sqlite'))
+ if (!extension_loaded('pdo_sqlite') || !extension_loaded('pdo')){
return get_string('sqliteextensionisnotpresentinphp', 'install');
+ }
return true;
}