@@ -1,21 +1,21 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | jRequire("PdoAdapterMysql.php"); |
| 3 | 3 | class PdoAdapterSqLiteFile extends PdoAdapterMysql { |
| 4 | - public $connection; |
|
| 5 | - public function __construct( $_srv, $_db, $_usr, $_pass ) { |
|
| 6 | - try { |
|
| 7 | - $this->connection = new PDO("sqlite:$_srv"); |
|
| 8 | - } catch( Exception $e ) { |
|
| 9 | - throw new JException($e->getMessage()); |
|
| 10 | - } |
|
| 11 | - } |
|
| 12 | - public function newTable( $_sql ) { |
|
| 13 | - try { |
|
| 14 | - $temp = $this->connection->exec($_sql); |
|
| 15 | - } catch (Exception $e) { |
|
| 16 | - throw new JException($e->getMessage()); |
|
| 17 | - } |
|
| 18 | - return $temp; |
|
| 19 | - } |
|
| 4 | + public $connection; |
|
| 5 | + public function __construct( $_srv, $_db, $_usr, $_pass ) { |
|
| 6 | + try { |
|
| 7 | + $this->connection = new PDO("sqlite:$_srv"); |
|
| 8 | + } catch( Exception $e ) { |
|
| 9 | + throw new JException($e->getMessage()); |
|
| 10 | + } |
|
| 11 | + } |
|
| 12 | + public function newTable( $_sql ) { |
|
| 13 | + try { |
|
| 14 | + $temp = $this->connection->exec($_sql); |
|
| 15 | + } catch (Exception $e) { |
|
| 16 | + throw new JException($e->getMessage()); |
|
| 17 | + } |
|
| 18 | + return $temp; |
|
| 19 | + } |
|
| 20 | 20 | } |
| 21 | 21 | ?> |
@@ -2,14 +2,14 @@ |
||
| 2 | 2 | jRequire("PdoAdapterMysql.php"); |
| 3 | 3 | class PdoAdapterSqLiteFile extends PdoAdapterMysql { |
| 4 | 4 | public $connection; |
| 5 | - public function __construct( $_srv, $_db, $_usr, $_pass ) { |
|
| 5 | + public function __construct($_srv, $_db, $_usr, $_pass) { |
|
| 6 | 6 | try { |
| 7 | 7 | $this->connection = new PDO("sqlite:$_srv"); |
| 8 | - } catch( Exception $e ) { |
|
| 8 | + } catch (Exception $e) { |
|
| 9 | 9 | throw new JException($e->getMessage()); |
| 10 | 10 | } |
| 11 | 11 | } |
| 12 | - public function newTable( $_sql ) { |
|
| 12 | + public function newTable($_sql) { |
|
| 13 | 13 | try { |
| 14 | 14 | $temp = $this->connection->exec($_sql); |
| 15 | 15 | } catch (Exception $e) { |
@@ -1,52 +1,52 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | requireComponents("Adapters"); |
| 3 | 3 | class Connection { |
| 4 | - public $database; |
|
| 5 | - public $info; |
|
| 6 | - public function __construct( $_object ) { |
|
| 7 | - if(!is_object($_object)) |
|
| 8 | - throw new JException("Parameter must be an object."); |
|
| 9 | - $this->setConnection( |
|
| 10 | - $_object->server, |
|
| 11 | - $_object->database, |
|
| 12 | - $_object->user, |
|
| 13 | - $_object->password, |
|
| 14 | - $this->getConnectionType($_object->engine) |
|
| 15 | - ); |
|
| 16 | - } |
|
| 17 | - protected function setConnection ( $_srv, $_db, $_usr, $_pass, $_type ) { |
|
| 18 | - switch ($_type) { |
|
| 19 | - case "mysqli": |
|
| 20 | - $this->database = new MysqliAdapter($_srv, $_db, $_usr, $_pass); |
|
| 21 | - break; |
|
| 22 | - case "postgresql": |
|
| 23 | - $this->database = new PostgresqlAdapter($_srv, $_db, $_usr, $_pass); |
|
| 24 | - break; |
|
| 25 | - case "pdo-sqlite-memory": |
|
| 26 | - $this->database = new PdoAdapterSqLiteMemory($_srv, $_db, $_usr, $_pass); |
|
| 27 | - break; |
|
| 28 | - case "pdo-sqlite-file": |
|
| 29 | - $this->database = new PdoAdapterSqLiteFile($_srv, $_db, $_usr, $_pass); |
|
| 30 | - break; |
|
| 31 | - case "pdo-mysql": |
|
| 32 | - default: |
|
| 33 | - $this->database = new PdoAdapterMysql($_srv, $_db, $_usr, $_pass); |
|
| 34 | - break; |
|
| 35 | - } |
|
| 36 | - $this->info = [ |
|
| 37 | - "srv" => $_srv, |
|
| 38 | - "db" => $_db, |
|
| 39 | - "usr" => $_usr, |
|
| 40 | - "pass" => $_pass, |
|
| 41 | - "type" => $_type |
|
| 42 | - ]; |
|
| 43 | - } |
|
| 44 | - protected function getConnectionType( $_type ) { |
|
| 45 | - $array = (array)$_type; |
|
| 46 | - foreach ($array as $key => $value) |
|
| 47 | - if($value) |
|
| 48 | - return $key; |
|
| 49 | - return "pdo"; |
|
| 50 | - } |
|
| 4 | + public $database; |
|
| 5 | + public $info; |
|
| 6 | + public function __construct( $_object ) { |
|
| 7 | + if(!is_object($_object)) |
|
| 8 | + throw new JException("Parameter must be an object."); |
|
| 9 | + $this->setConnection( |
|
| 10 | + $_object->server, |
|
| 11 | + $_object->database, |
|
| 12 | + $_object->user, |
|
| 13 | + $_object->password, |
|
| 14 | + $this->getConnectionType($_object->engine) |
|
| 15 | + ); |
|
| 16 | + } |
|
| 17 | + protected function setConnection ( $_srv, $_db, $_usr, $_pass, $_type ) { |
|
| 18 | + switch ($_type) { |
|
| 19 | + case "mysqli": |
|
| 20 | + $this->database = new MysqliAdapter($_srv, $_db, $_usr, $_pass); |
|
| 21 | + break; |
|
| 22 | + case "postgresql": |
|
| 23 | + $this->database = new PostgresqlAdapter($_srv, $_db, $_usr, $_pass); |
|
| 24 | + break; |
|
| 25 | + case "pdo-sqlite-memory": |
|
| 26 | + $this->database = new PdoAdapterSqLiteMemory($_srv, $_db, $_usr, $_pass); |
|
| 27 | + break; |
|
| 28 | + case "pdo-sqlite-file": |
|
| 29 | + $this->database = new PdoAdapterSqLiteFile($_srv, $_db, $_usr, $_pass); |
|
| 30 | + break; |
|
| 31 | + case "pdo-mysql": |
|
| 32 | + default: |
|
| 33 | + $this->database = new PdoAdapterMysql($_srv, $_db, $_usr, $_pass); |
|
| 34 | + break; |
|
| 35 | + } |
|
| 36 | + $this->info = [ |
|
| 37 | + "srv" => $_srv, |
|
| 38 | + "db" => $_db, |
|
| 39 | + "usr" => $_usr, |
|
| 40 | + "pass" => $_pass, |
|
| 41 | + "type" => $_type |
|
| 42 | + ]; |
|
| 43 | + } |
|
| 44 | + protected function getConnectionType( $_type ) { |
|
| 45 | + $array = (array)$_type; |
|
| 46 | + foreach ($array as $key => $value) |
|
| 47 | + if($value) |
|
| 48 | + return $key; |
|
| 49 | + return "pdo"; |
|
| 50 | + } |
|
| 51 | 51 | } |
| 52 | 52 | ?> |