[PHP][フレームワーク]CodeIgniterスレ
■ このスレッドは過去ログ倉庫に格納されています
0431nobodyさん
2008/07/15(火) 06:26:58ID:???class SafeMarker {
private $_str;
public function __construct($str) { $this->_str = $str; }
public function __toString() { return $this->_str; }
}
function mark_as_safe($str) {
return new SafeMarker($str);
}
モデルの中でこんな感じで使ってますよ
$this->load->helper('database');
$this->db->set('foo', $bar);
$this->db->set('created_at', mark_as_safe('NOW()'));
$this->db->insert('mytable');
CI_DB_driver#escape を読むとわかるけど、gettype で 'string' でも 'boolean' でも
NULL でもない値はスルーしてくれるので、オブジェクトでラップすると通る。
ただし __toString はPHP5からかな。
一種のhackなので、NOW()みたいな安全だとわかっているものにしか使いませんが。
■ このスレッドは過去ログ倉庫に格納されています