I want to point a question for Qiang and Yii team.
The actual CDbConnection actually is not inherited by any driver, we always use an instance of the CDbConnection.
However, I was thinking if it is not better USE the inheritance, so we would have an CDbConnection (defaults to mysql), CPgsqlConnection, CMssqlConnection, OOciConnection, etc.
I explain: This would make the customizing for a particular database more flexible. the actual CDbConnection is with coding like
if($driver==='mssql' || $driver==='dblib')
I think it is not a good approach to make diferente codes in CdbConnection based on the driver type.
For example, I am improving Oracle driver for set the letter-case and the date format. I could do this directly into CdbConnection (and put one more exception into the code), but I preferred to extend the CdbConnection class like this:
class COciConnection extends CDbConnection{
protected function initConnection($pdo)
{
parent::initConnection($pdo);
// set the case
$pdo->setAttribute(PDO::ATTR_CASE,PDO::CASE_UPPER);
//set date format
$stmt=$pdo->prepare("alter session set NLS_DATE_FORMAT='dd/MM/yyyy HH24:MI:SS'");
$stmt->execute();
}
}
So, I have escapsulated the especific code for Oracle into this new class. I am sure that will be usefull for MsSQL implementation, too.
Also, extending CDbConnection and having CMysqlConnection, COciConnection and etc. can allows Yii to make connections in config.php easier. Instead of:
'db'=>array(
'connectionString'=>'oci:dbname=MYDB',
'username'=>'USER',
'password'=>'PASS',
'class'=>'COciConnection',
),
we could have
'db'=>array(
'class'=>'COciConnection',
'dbname'=MYDB',
'username'=>'USER',
'password'=>'PASS',
),
Ok, the former way is not complicated, but I guess the last way is a bit more clear.
I know that ACTUALLY is possible to do what I proposed, I am wondering if this approach could be the default behavior in the future Yii db implementation (1.1)