Active Record Classigniter Paste From

I have a news tracking site that we have moved to Codeigniter, I have encountered a problem using Codeigniter Active Record - I don’t have enough knowledge to understand this.

In the old code - we insert and inside the insert do SELECT FROM to get the value for one insert field

$this->db->query("INSERT INTO news_item_keywords_link (news_item_keyword, keyword) SELECT $version_id, keyword FROM news_item_keywords_link WHERE news_item_keyword=$old_version 

I tried to do this using Active Record, and I cannot figure out how to do this, or maybe you cannot do it using Active Record.

I tried several things, my question is how do you do inline FROM in an INSERT statement with Active Record. I tried this way and it did not help to get a syntax error, any suggestions.

 if ($this->db->insert('news_item_keywords', Array( 'news_item_keyword' => $version_id, 'keyword' => $this-db->select('keyword') ->from('news_item_keywords') ->where('news_item_keyword', $old_version); ))) { 

Should I install the ORM library to extend functionality? If so, is the ORM library recommended?

+4
source share
1 answer

The 1st thing loads the model into the controller ...

Model:

 function add($data){ $this->insert("tablename",$data); } function select_keyword($oldversion){ $this->db->select("keyword"); $this->db->where("news_item_keywords",$oldversion); $this->db->get("news_item_keywords"); } 

Controller:

 function create(){ $data = array('news_item_keyword' => $version_id, 'news_item_keywords' => $this->modelname->select_keyword("oldversion") ); $this->modelname->insert($data);//successful! } 
0
source

All Articles