I am trying to use the CDbmessageSource with sql server. If I retrieve the translation outside of the framework, it looks like this: actualización. Using Yii::t it looks like this: actualizaci�n. The message and translation columns are ntext to accomodate for utf8. Notice I am converting the ntext coluns to text columns in the query otherwise I would get sql server error.
Non Yii code:
$mssql = new PDO(‘dblib:host=JUSSLCITWS02;dbname=dbname’,‘user’,‘pass’);
As far as I know, the only way to retrieve ntext values from the sql server db is to cast them to text or in the case of nvarchar to varchar.
Yii puts this line in the head tag: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> Which causes utf8 characters cast to text to display funny.
I need the pages in utf8, so how do I get around this wonderful feature of sql server?
When I see correct in db interface and then incorrect in Yii page (or viceversa) I know that a query ‘SET NAMES utf8’ is needed in mysql.
I don’t know the equivalent for mysql, but I can advice a dirty solution (with whom I worked fine for 2 years).
You can try building a simple interface for instert your translations with an Yii interface. Like that there will always been the mismatch, but at least the translation will be correctly shown in your application and incorrectly in db.
That is not a solution, but allows you to move forward.
In our languages (I am italian) there are only a few not-ascii character, and so you can even don’t care of it (like I did for years).
But when you go working in russia… you have to learn how to work correctly with encoding
initSQLs does not seem to come with Yii 1.1 and returns: Property "CDbConnection.initSQLs" is not defined. (/home/yourownb/framework/base/CComponent.php:173) Is there a work around for this older version of Yii?
I am having an issue with German names such as Köln and cannot match them against DB records and I think initSQLs is what I need but is not supported by Yii 1.1
Hmm. charset should actually do that for you. But it’s only used for sqlite, despite the comment tells otherwhise.
/**
* Initializes the open db connection.
* This method is invoked right after the db connection is established.
* The default implementation is to set the charset for MySQL and PostgreSQL database connections.
* @param PDO the PDO instance
*/
protected function initConnection($pdo)
{
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if($this->emulatePrepare && constant('PDO::ATTR_EMULATE_PREPARES'))
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,true);
if($this->charset!==null)
{
if(strcasecmp($pdo->getAttribute(PDO::ATTR_DRIVER_NAME),'sqlite'))
$pdo->exec('SET NAMES '.$pdo->quote($this->charset));
}
if($this->initSQLs!==null)
{
foreach($this->initSQLs as $sql)
$pdo->exec($sql);
}
}
Application is too big to re-write. But added the initSQLs check to my older framework. I think its not too risky to do so despite it is against Yii best practices…works as a charm with 1.1.0 now.
Mike could be quite right that it should have been handled by the charset.
That’s what scares me! If you think that all my current DAO and AR will work on the new skeleton I might be willing to upgrade…otherwise I will leave it for some time in the future.