2011/07/15

codeigniterでpostgresqlの設定 database.php

$db['test']['username'] = "username";
$db['test']['password'] = "passwd";
$db['test']['database'] = "db_name";
$db['test']['dbdriver'] = "postgre";
$db['test']['dbprefix'] = "";
$db['test']['pconnect'] = FALSE;
$db['test']['db_debug'] = TRUE;
$db['test']['cache_on'] = FALSE;
$db['test']['cachedir'] = "";
$db['test']['char_set'] = "utf8";
$db['test']['dbcollat'] = "utf8_general_ci";

pconeect 持続的接続は使用しない方がいい。
OSのプロセスが残って不安定になる。

2011/07/09

Yiiでマルチバイト文字でのバリデーションを行う方法

Yii 1.1から以下のようにルールにencodingを渡すことにより
マルチバイト文字での長さチェック等ができるようです。

array('string', 'length', 'max'=>10 , "encoding" => Yii::app()->charset)

参考URL
http://www.yiiframework.com/forum/index.php?/topic/2721-yii-multibyte-safe/

2011/07/08

codeigniterでpostgresqlで文字化けが治らない場合の対処

またしてもcodeingiterのポスグレのバグを発見しました(通算3つ目)

・phpからpostgresにclient_encodingを送っていない

postgresqlはアプリケーション側でclient_encodingを設定していないと
設定ファイルに書いてあるデフォルトのclient_encodingに変換して結果を返してきます。

修正箇所は
system/database/drivers/postgre/postgre_driver.php

145行目 db_set_charset
中身は無しでコメントにて
// @todo - add support if needed
ふざけんなと( ゚Д゚)ヴォケ!!

pg_set_client_encoding($this->conn_id , $this->char_set);

これで文字化けが直りました。
しかし本当にcodeigniterのpostgresドライバは信用出来ない。
他にも色々バグありそう

2011/07/05

yiiでwhere in でデータを取得

ちょっと詰まった。
フォーラムの記事を参考にして解決
problem with createInCondition

$criteria = new CDbCriteria();
$criteria->addInCondition('id', array(1,2,3));
$result=User::model()->findAll($criteria);

createInCriteria()の第4引数にパラメータうんぬんって書いてあるけど
第4引数はprefixでした。
使ってないので僕の場合は不要。