Changeset 2432
- Timestamp:
- 04/18/2008 04:02:05 AM
- Files:
-
- trunk/HISTORY (modified) (1 diff)
- trunk/framework/Data/TDbConnection.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/HISTORY
r2427 r2432 39 39 ENH: Ticket#757 - TDateFormat and TNumberFormat now implement IDataRenderer (Qiang) 40 40 ENH: Ticket#783 - Added date/time type support to soap implementation (Hongliang) 41 ENH: Ticket#800 - Added database connection charset for MySql (donkee) 41 42 ENH: Active Record supports multiple foreign references of the same table (Wei) 42 43 ENH: Added TDbCommand.queryColumn() (Qiang) trunk/framework/Data/TDbConnection.php
r2400 r2432 28 28 * and {@link setPassword Password}. 29 29 * 30 * Since 3.1.2, the connection charset can be set (for MySQL databases only) using the {@link setCharset Charset} property. 31 * 30 32 * The following example shows how to create a TDbConnection instance and establish 31 33 * the actual connection: … … 83 85 private $_username=''; 84 86 private $_password=''; 87 private $_charset=''; 85 88 private $_attributes=array(); 86 89 private $_active=false; … … 93 96 * instance is created. Set {@link setActive Active} property to true 94 97 * to establish the connection. 98 * Since 3.1.2, you can set the charset for MySql connection 99 * 95 100 * @param string The Data Source Name, or DSN, contains the information required to connect to the database. 96 101 * @param string The user name for the DSN string. 97 102 * @param string The password for the DSN string. 103 * @param string Charset used for DB Connection (MySql only). If not set, will use the default charset of your database server 98 104 * @see http://www.php.net/manual/en/function.PDO-construct.php 99 105 */ 100 public function __construct($dsn='',$username='',$password='' )106 public function __construct($dsn='',$username='',$password='', $charset='') 101 107 { 102 108 $this->_dsn=$dsn; 103 109 $this->_username=$username; 104 110 $this->_password=$password; 111 $this->_charset=$charset; 105 112 } 106 113 … … 162 169 $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 163 170 $this->_active=true; 171 $this->setConnectionCharset(); 164 172 } 165 173 catch(PDOException $e) … … 180 188 } 181 189 190 /* 191 * Set the database connection charset. 192 * Only MySql databases are supported for now. 193 * @since 3.1.2 194 */ 195 protected function setConnectionCharset() 196 { 197 if ($this->_charset === '' || $this->_active === false) 198 return; 199 switch ($this->_pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) 200 { 201 case 'mysql': 202 $stmt = $this->_pdo->prepare('SET CHARACTER SET ?'); 203 $stmt->execute(array($this->_charset)); 204 break; 205 } 206 } 207 182 208 /** 183 209 * @return string The Data Source Name, or DSN, contains the information required to connect to the database. … … 229 255 } 230 256 257 /** 258 * @return string the charset used for database connection. Defaults to emtpy string. 259 */ 260 public function getCharset () 261 { 262 return $this>_charset; 263 } 264 265 /** 266 * @param string the charset used for database connection 267 */ 268 public function setCharset ($value) 269 { 270 $this->_charset=$value; 271 $this->setConnectionCharset(); 272 } 273 231 274 /** 232 275 * @return PDO the PDO instance, null if the connection is not established yet
