I have a custom CodeIgniter library where I need to run a few database operations.
To get access to the database, I perform this command, which I learned here on StackOverflow:
$this->CI =& get_instance();
I know it's working, since this command works:
$drop_query = "DELETE FROM product_images WHERE product_id = " . $this->CI->db->escape($product_id);
$this->CI->db->query($drop_query); // Tested, this works.
However, insert_batch does not work at all. No FALSE returned, no errors... nothin. It just dies.
$master_insert_array = array(
array(
'product_id' => $product_id,
'thumb_type' => 'original',
'filename' => $orig_file_name
),
array(
'product_id' => $product_id,
'thumb_type' => 'small',
'filename' => $small_file_name
) // Truncating the rest of this...
);
error_log("update_product_image_db: Insert_Batch Coming up:");
$batch_success = $this->CI->db->insert_batch('product_images', $master_insert_array);
error_log("\n\n".$this->CI->db->last_query()."\n");
*EDIT: It turns out that my $product_id was failing foreign key constraints, making the batch_insert fail.*
The second error_log never gets run after it fails. The script just dies.
So how can I get insert_batch to properly return me a FALSE, an error, or something other than flat out fails?
*UPDATE: I've also tried putting this into a try/catch block, with no success. If it fails foreign key constraint, it aborts my entire script. It is of my current opinion that insert_batch is a poorly-written function*
Thanks!
echo $this->db->last_query()just before the lasterror_logand see the output.