diff options
author | knut <> | 2008-08-14 08:30:41 +0000 |
---|---|---|
committer | knut <> | 2008-08-14 08:30:41 +0000 |
commit | 9b940a6b86bf661eb66ad5752ecde1ec7a6358a8 (patch) | |
tree | 5f665fe5b9554bb182c66d140da6d09c7198b20c /framework/Data/TDbConnection.php | |
parent | c7c5ad3a32287210f8127f0986230a13a07b3c18 (diff) |
fixed #904
Diffstat (limited to 'framework/Data/TDbConnection.php')
-rw-r--r-- | framework/Data/TDbConnection.php | 101 |
1 files changed, 51 insertions, 50 deletions
diff --git a/framework/Data/TDbConnection.php b/framework/Data/TDbConnection.php index 97ea90ba..5489c7fd 100644 --- a/framework/Data/TDbConnection.php +++ b/framework/Data/TDbConnection.php @@ -4,7 +4,7 @@ *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.pradosoft.com/
- * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Data
@@ -26,10 +26,10 @@ Prado::using('System.Data.TDbCommand'); * To establish a connection, set {@link setActive Active} to true after
* specifying {@link setConnectionString ConnectionString}, {@link setUsername Username}
* and {@link setPassword Password}.
- * - * Since 3.1.2, the connection charset can be set (for MySQL and PostgreSQL databases only) - * using the {@link setCharset Charset} property. The value of this property is database dependant. - * e.g. for mysql, you can use 'latin1' for cp1252 West European, 'utf8' for unicode, ... + *
+ * Since 3.1.2, the connection charset can be set (for MySQL and PostgreSQL databases only)
+ * using the {@link setCharset Charset} property. The value of this property is database dependant.
+ * e.g. for mysql, you can use 'latin1' for cp1252 West European, 'utf8' for unicode, ...
*
* The following example shows how to create a TDbConnection instance and establish
* the actual connection:
@@ -85,7 +85,7 @@ class TDbConnection extends TComponent {
private $_dsn='';
private $_username='';
- private $_password=''; + private $_password='';
private $_charset='';
private $_attributes=array();
private $_active=false;
@@ -96,12 +96,12 @@ class TDbConnection extends TComponent * Constructor.
* Note, the DB connection is not established when this connection
* instance is created. Set {@link setActive Active} property to true
- * to establish the connection. - * Since 3.1.2, you can set the charset for MySql connection + * to establish the connection.
+ * Since 3.1.2, you can set the charset for MySql connection
*
* @param string The Data Source Name, or DSN, contains the information required to connect to the database.
* @param string The user name for the DSN string.
- * @param string The password for the DSN string. + * @param string The password for the DSN string.
* @param string Charset used for DB Connection (MySql & pgsql only). If not set, will use the default charset of your database server
* @see http://www.php.net/manual/en/function.PDO-construct.php
*/
@@ -109,7 +109,7 @@ class TDbConnection extends TComponent {
$this->_dsn=$dsn;
$this->_username=$username;
- $this->_password=$password; + $this->_password=$password;
$this->_charset=$charset;
}
@@ -169,7 +169,8 @@ class TDbConnection extends TComponent $this->_pdo=new PDO($this->getConnectionString(),$this->getUsername(),
$this->getPassword(),$this->_attributes);
$this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $this->_active=true; + $this->_pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+ $this->_active=true;
$this->setConnectionCharset();
}
catch(PDOException $e)
@@ -188,27 +189,27 @@ class TDbConnection extends TComponent $this->_pdo=null;
$this->_active=false;
}
- - /* - * Set the database connection charset. - * Only MySql databases are supported for now. - * @since 3.1.2 - */ - protected function setConnectionCharset() - { - if ($this->_charset === '' || $this->_active === false) - return; - switch ($this->_pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) - { - case 'mysql': - $stmt = $this->_pdo->prepare('SET CHARACTER SET ?'); - break; - case 'pgsql': - $stmt = $this->_pdo->prepare('SET client_encoding TO ?'); - break; - } - $stmt->execute(array($this->_charset)); - } +
+ /*
+ * Set the database connection charset.
+ * Only MySql databases are supported for now.
+ * @since 3.1.2
+ */
+ protected function setConnectionCharset()
+ {
+ if ($this->_charset === '' || $this->_active === false)
+ return;
+ switch ($this->_pdo->getAttribute(PDO::ATTR_DRIVER_NAME))
+ {
+ case 'mysql':
+ $stmt = $this->_pdo->prepare('SET CHARACTER SET ?');
+ break;
+ case 'pgsql':
+ $stmt = $this->_pdo->prepare('SET client_encoding TO ?');
+ break;
+ }
+ $stmt->execute(array($this->_charset));
+ }
/**
* @return string The Data Source Name, or DSN, contains the information required to connect to the database.
@@ -258,23 +259,23 @@ class TDbConnection extends TComponent {
$this->_password=$value;
}
- - /** - * @return string the charset used for database connection. Defaults to emtpy string. - */ - public function getCharset () - { - return $this>_charset; - } - - /** - * @param string the charset used for database connection - */ - public function setCharset ($value) - { - $this->_charset=$value; - $this->setConnectionCharset(); - } +
+ /**
+ * @return string the charset used for database connection. Defaults to emtpy string.
+ */
+ public function getCharset ()
+ {
+ return $this>_charset;
+ }
+
+ /**
+ * @param string the charset used for database connection
+ */
+ public function setCharset ($value)
+ {
+ $this->_charset=$value;
+ $this->setConnectionCharset();
+ }
/**
* @return PDO the PDO instance, null if the connection is not established yet
@@ -597,4 +598,4 @@ class TDbNullConversionMode extends TEnumerable const EmptyStringToNull='EmptyStringToNull';
}
-?> +?>
|