note:
an example function CDbExpression() to handle MS-SQL getdate() vs MySQL NOW() ;
you can have whatever functions here which would be used application wide.
add files in \protected\components\functions\Fn.php
class fn extends CApplicationComponent
{
public function init() {
}
/**
* handle NOW() function for ms-sql server
* @param string $exp
* @return string
*/
public static function CDbExpression($exp, $db='db') {
if($exp == 'NOW()') {
if (substr(Yii::app()->{$db}->connectionString, 0, 7) === 'sqlsrv:') {
return new CDbExpression('GETDATE()');
}
}
//otherwise
return new CDbExpression($exp);
}
}
in protected\config\main.php add line
'import'=>array(
//~~
'application.components.functions.*',
//~~
in any code, replace
new CDbExpression('NOW()');
with
fn::CDbExpression('NOW()');