[eluser]zorka[/eluser]
Hello,
I'm relatively new to Code igniter and PHP in general. I'm working on an app that does alot of inserts into a databases. If at all possible, I'd like just to try an insert, then check for a return value to see whether the insert worked OR whether it did not (due to a constraint being violated, such as duplicate UNIQUE or PRIMARY key)... This makes for simpler code and I believe, more efficient design than doing a SELECT STATEMENT (i.e. checking to see if a given UNIQUE field exists), then the INSERT statement if successful.
Something like:
$returnVal=$db->insert('users',$user);
if ($returnVal) {
echo "success";
}
How do I do this? Am I correct in my assumption that this is more efficient than doing a select (traversing the dbase searching for the record) then inserting (traversing again to insert it)?
ThanX,
Ben