12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php namespace System\DB;
- class Connector {
-
- public static $options = array(
- \PDO::ATTR_CASE => \PDO::CASE_LOWER,
- \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
- \PDO::ATTR_ORACLE_NULLS => \PDO::NULL_NATURAL,
- \PDO::ATTR_STRINGIFY_FETCHES => false,
- );
-
- public static function connect($config)
- {
-
-
-
- if ($config->driver == 'sqlite')
- {
- return new \PDO('sqlite:'.APP_PATH.'db/'.$config->database.'.sqlite', null, null, static::$options);
- }
-
-
-
- elseif ($config->driver == 'mysql' or $config->driver == 'pgsql')
- {
- $connection = new \PDO($config->driver.':host='.$config->host.';dbname='.$config->database, $config->username, $config->password, static::$options);
-
-
-
- if (isset($config->charset))
- {
- $connection->prepare("SET NAMES '".$config->charset."'")->execute();
- }
- return $connection;
- }
-
-
-
- else
- {
- throw new \Exception('Database driver '.$config->driver.' is not supported.');
- }
- }
- }
|