Welcome Guest, Not a member yet? Register   Sign In
INSERT IGNORE INTO
#1

[eluser]Sire[/eluser]
Is there a way to use Active Record $this->db->insert() to achieve an 'INSERT IGNORE INTO' statement?
#2

[eluser]Sire[/eluser]
In the absence of a built-in way to manage it, I came up with:

MySQL version
Code:
$insert_query = $this->db->insert_string('links',$link_data);
$insert_query = str_replace('INSERT INTO','INSERT IGNORE INTO',$insert_query);
$this->db->query($insert_query);

SQLITE3 version
Code:
$insert_query = $this->db->insert_string('links',$link_data);
$insert_query = str_replace('INSERT INTO','INSERT OR IGNORE INTO',$insert_query);
$this->db->query($insert_query);

Would you write it differently?
#3

[eluser]João Ramos[/eluser]
I've had the same situation and used your approach. It's much cleaner using it on an active record than writing the whole SQL query. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB