activerecord - How to insert records using select in codeigniter active record -


I want to implement an SQL query using the CodeIgniter Active Record class. The query looks like this ..

  INSERT California_Authurator (au_id, au_lname, au_fname) SELECT au_id, au_lname, au_fname Whereas the stat = 'ca'  

Is the codeIgniter possible without using the $$-> db-> query method?

Solution :

  $ this-> DB- & gt; Select ('au_id, au_lname, au_fname'); $ This- & gt; Db- & gt; ('California_authors'); $ This- & gt; Db- & gt; Where ('state', 'ca'); $ Query = $ this- & gt; Db- & gt; get receive (); If ($ query-> num_rows ()) {$ new_author = $ query- & gt; Result_are (); Foreign ($ new_author $ $ = $ as author $ $) $ {$ this- & gt; Db- & gt; Enter ("writers", $ author); }}  

Regards

I think that you SELECT ... INSERT query, there is no way to do this on the Active Record class, but there are two ways to do this

1)

 < Code> $ query = $ this- & gt; Db- & gt; Query ('INSERT California_Atherres (au_id, au_lname, au_fname) SELECT au_id, au_lname, au_fname WHERE state = \' CA \ 'from authors);  

As you say

and 2) you can do that, which the whistle said,

  $ of Select = $ it - & gt; DB- & gt; Select ('au_id, au_lname, au_fname') - & gt; Where ('state', 'ca') & gt; Receive ('California' author '); If ($ select-> num_rows ()) {$ insert = $ this- & gt; Db- & gt; Insert ('California' author ', $ select- & gt; Results_array ()); } Other {/ * Nothing to insert * /  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -