CodeIgniter Active Record クラスを使用して SQL クエリを実装したいと考えています。クエリは次のようになります。
INSERT california_authors (au_id, au_lname, au_fname)
SELECT au_id, au_lname, au_fname
FROM authors
WHERE State = 'CA'
$this->db->query メソッドを使用せずに CodeIgniter でこれは可能ですか?
解決策:
$this->db->select('au_id, au_lname, au_fname');
$this->db->from('california_authors');
$this->db->where('state', 'CA');
$query = $this->db->get();
if($query->num_rows()) {
$new_author = $query->result_array();
foreach ($new_author as $row => $author) {
$this->db->insert("authors", $author);
}
}
よろしく