diff options
author | wei <> | 2006-02-22 04:01:28 +0000 |
---|---|---|
committer | wei <> | 2006-02-22 04:01:28 +0000 |
commit | 41c5b7e566c0019d0b8e0c9399b780a95ad44113 (patch) | |
tree | 7a0d6eb6604b1f0fc933defd960200e712266cb7 /framework/DataAccess/TCreoleProvider.php | |
parent | fceb3741d3b0c1e00e81a4a24caf7d49a86896b4 (diff) |
Adding DataAccess modules.
Diffstat (limited to 'framework/DataAccess/TCreoleProvider.php')
-rw-r--r-- | framework/DataAccess/TCreoleProvider.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/framework/DataAccess/TCreoleProvider.php b/framework/DataAccess/TCreoleProvider.php new file mode 100644 index 00000000..d45818fa --- /dev/null +++ b/framework/DataAccess/TCreoleProvider.php @@ -0,0 +1,84 @@ +<?php
+
+Prado::using('System.DataAccess.TDatabaseProvider');
+Prado::using('System.DataAccess.TDatabaseException');
+
+Prado::using('System.DataAccess.creole.*');
+
+class TCreoleProvider extends TDatabaseProvider
+{
+ private $_connection = null;
+
+ public function getConnection()
+ {
+ if(is_null($this->_connection))
+ $this->_connection = new TCreoleConnection($this);
+ return $this->_connection;
+ }
+
+ public function getConnectionString()
+ {
+ if(strlen(parent::getConnectionString()) > 0)
+ return parent::getConnectionString();
+ else
+ return $this->generateConnectionString();
+ }
+
+ protected function generateConnectionString()
+ {
+ $driver = $this->getDriver();
+ $user = $this->getUsername();
+ $pass = $this->getPassword();
+ $host = $this->getHost();
+ $database = $this->getDatabase();
+
+ $pass = strlen($pass) > 0 ? ':'.$pass : '';
+ $username_password = strlen($user) > 0 ? $user.$pass.'@' : '';
+ $database = strlen($database) > 0 ? '/'.$database : '';
+
+ return "{$driver}://{$username_password}{$host}{$database}";
+ }
+}
+
+class TCreoleConnection extends TDbConnection
+{
+ private $_connection = null;
+
+ protected function beginDbTransaction()
+ {
+ }
+
+ /**
+ * Closes the connection to the database.
+ */
+ public function close()
+ {
+ $this->_connection->close();
+ }
+
+ public function prepare($statement)
+ {
+ return $this->_connection->prepareStatement($statement);
+ }
+
+ public function execute($sql,
+
+ /**
+ * Opens a database connection with settings provided in the ConnectionString.
+ */
+ public function open()
+ {
+ if(is_null($this->_connection))
+ {
+ $connectionString = $this->getProvider()->getConnectionString();
+ if(strlen($connectionString) < 1 || strcmp($connectionString,'://') === 0)
+ throw new TDbConnectionException('db_driver_required');
+ $class = 'System.DataAccess.creole.creole.Creole';
+ $creole = Prado::createComponent($class);
+ $this->_connection = $creole->getConnection($connectionString);
+ }
+ return $this->_connection;
+ }
+}
+
+?>
\ No newline at end of file |