Is this possible / true?
For instance, if I want to update a row with the id of 1, but no row exists, will this function (update function) automatically insert a new row with the given data? Is there a parameter to enable this?
If not, what would be the best way to handle this (if possible) without using a separate function to evaluate the table and return bool if the row exists. (Then UPDATEing or INSERTing from there)
Not much of an issue.. Just looking for clarification and wondering if anyone knows about this.
I found a good solution in this link, I hope it helps if anyone is still looking for a solution in codeigniter:
$sql = 'INSERT INTO menu_sub (id, name, desc, misc)
VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
name=VALUES(name),
desc=VALUES(desc),
misc=VALUES(misc)';
$query = $this->db->query($sql, array( $id,
$this->validation->name,
$this->validation->desc,
$this->validation->misc
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With