protected function createConnection($driver, $host, $name, $user, $password, $port = null)
{
if (!$this->validateDriver($driver)) {
throw new Exception('DATABASE WRAPPER::error, the database you wish to connect to is not supported by your install of PHP.');
}
// attempt to create pdo object and connect to the database
try {
//@TODO the following drivers are NOT supported yet: odbc, ibm, informix, 4D
// build the connection string from static constants based on the selected PDO Driver.
if ($driver == "sqlite" || $driver == "sqlite2") {
$connection_string = $driver . ':' . $host;
} elseif ($driver == "sqlsrv") {
$connection_string = "sqlsrv:Server=" . $host . ";Database=" . $name;
} elseif ($driver == "firebird" || $driver == "oci") {
$connection_string = $driver . ":dbname=" . $name;
} else {
$connection_string = $driver . ':host=' . $host . ';dbname=' . $name;
}
// add the port if one was specified
if (!empty($port)) {
$connection_string .= ";port={$port}";
}
// initialize the PDO object
$new_connection = new PDO($connection_string, $user, $password);
// set the error mode
$new_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// return the new connection
return $new_connection;
} catch (PDOException $e) {
if (self::$LOG_ERRORS == true) {
error_log('DATABASE WRAPPER::' . print_r($e, true));
}
$this->pdo_exception = $e;
return false;
} catch (Exception $e) {
if (self::$LOG_ERRORS == true) {
error_log('DATABASE WRAPPER::' . print_r($e, true));
}
$this->pdo_exception = $e;
return false;
}
}