CodeIgniter でのクエリ:
$this->db->select('comments.created_at, comments.section_id, comments.submittedby_id, users.username, comments.text, sections.name');
$this->db->order_by('comments.created_at', 'desc');
$this->db->where('comments.submittedby_id', 'users.user_id');
$this->db->where('comments.section_id', 'sections.id');
$query = $this->db->get(array('comments', 'users', 'sections'),10);
SQL リクエストの生成:
選択し
pdb_comments
ます。created_at
、pdb_comments
。section_id
、pdb_comments
。submittedby_id
、pdb_users
。username
、pdb_comments
。text
、pdb_sections
。name
FROM (pdb_comments
,pdb_users
,pdb_sections
) WHEREpdb_comments
.submittedby_id
= 'users.user_id' ANDpdb_comments
.section_id
= 'sections.id' ORDER BYpdb_comments
.created_at
desc LIMIT 10
問題は、データベース プレフィックス ( ) が句pdb_
に追加されないことです。WHERE
を追加してプレフィックスを手動で挿入できます$this->db->dbprefix
が、これでは主な問題は解決しません。
引用符:
`pdb_comments`.`submittedby_id` = 'pdb_users.user_id'
右側の引用符は正確ではなく、結果は 0 です。CodeIgniter に where 句の後半をテーブルの一部として認識させる方法はありますか? これにより、データベースのプレフィックスを追加し、2 つの結合を回避して引用符を適切に配置しますか? これを行う別の方法はありますか?前もって感謝します。
--
ジョン