Essentially I've got a table with a few posts marked Unique. I've got a script that dumps a lot of values in to the table having a command such as this:

$this->db->query("INSERT INTO `table` (`col1`, `col2`, `col3`) VALUES (`val1`, `val2`, `val3`)");

Once in awhile my script will attempt to place a row which may violate the originality of among the posts. However, rather than leading to the script to abort having a database error, I'd want it to continue, possible outputting just a little message. Essentially I am searching for the codeigniter same as

mysql_query("INSERT blah blah blah") or print("fail");

Thanks!
Mala

Yeah, required us a while too and annoyed the hell from me:

$db['default']['db_debug'] = FALSE;

... in config/database.php - hinders the mistake page.

Following a query went, make use of this to check on to have an error:

if (!empty($this->db->_error_message())) {
    echo "FAIL";
}

I understand you have an answer, but thought this can be helpful for other people viewing this too.

Allow the database perform the meet your needs:

$this->db->query("INSERT IGNORE INTO `table` (`col1`, `col2`, `col3`) VALUES (`val1`, `val2`, `val3`)");

If you use Place IGNORE, such things as duplicate key errors become alerts rather than errors, which give your queries run without stifling the flow of the script.

You can then perform a

SHOW WARNINGS;

in the end the queries have go to see what alerts happened.

http://dev.mysql.com/doc/refman/5.1/en/insert.html

An identical question was already answered here.