• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple INSERT INTO in one $this->db->query

#1
[eluser]EEssam[/eluser]
Hi,

Any idea why this is not working?

Code:
$this->db->query("INSERT INTO `category` VALUES ('1', '0', 'hhh', '1');
INSERT INTO `category` VALUES ('2', '0', 'fff', '1');");

Thanks.

#2
[eluser]Randy Casburn[/eluser]
Assuming you are using the MySQL driver, eventually, this is the command that is run by CI:

Code:
return @mysql_query($sql, $this->conn_id);

This implies, then, that your SQL statements (INSERT or otherwise) must be treated as standalone statements and cannot be compounded as you've attempted to do.

Hope this has been helpful,

Randy

#3
[eluser]EEssam[/eluser]
I see. Thank you.

#4
[eluser]Randy Casburn[/eluser]
Also, leave the semi-colons off your SQL statements too ;-)

Randy

#5
[eluser]EEssam[/eluser]
No, here is my model function now:

Code:
function insert_default_data($data)
    {
        foreach ($data as $queries)
        {
            $queries = explode(';', $queries);

            foreach ($queries as $query)
            {
                if ($query != '')
                {
                    $this->db->query($query);
                }
            }
        }
    }

#6
[eluser]Randy Casburn[/eluser]
To each their own my friend. You code may become difficult to maintain down the road. But it is certainly innovative.

Randy


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.