Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM - How to INSERT INTO from SELECT
#1

[eluser]Unknown[/eluser]
Hello,
Can somebody provide some guidance on hot to execute a query like shown here:

Code:
INSERT INTO tableA (A,B,C,D,E,F)
SELECT A,B,C,D,E
FROM tableB
WHERE a = 'Y' AND DATE( B ) = DATE(DATE(now( )) + CAST(B AS SIGNED))

I found some examples but they mention that I need to first to create a container Array, then a db->select, push query results into container array and then a db->insert, as shown below.
However that seems counterproductive or time consuming, and adds complexity to the code (at lest from my pint of view)

Code:
...
$insert =   array();
$this->db->select("")->from('');
$this->db->where(array('A' => 'Y', DATE( 'B' ) => DATE(DATE(now( )) + CAST('C' AS SIGNED))));        
$resultset = $this->db->get()->result_array();

foreach($resultset as $result){
  array_push($insert, array(
    ''     =>  $reminder[''],
    ''       =>  $reminder[''],
    ''         =>  $reminder[''],
    ...
  ));
}

$this->db->insert('', $insert);
...
Hope I'm not miss-understanding here




Theme © iAndrew 2016 - Forum software by © MyBB