From PHP, I am calling a SQL stored procedure. The stored procedure checks the database, and either inserts the data if it's new, or modifies data that already exists.
I'm getting an error that one of my parameters is of an incorrect data type. I can't really control this because of where the data is coming from. I am calling the stored procedure hundreds, or thousands of times looping through an array of data, and I only get this error for a couple of records out of the batch.
What is the proper way to handle this error in the stored procedure? If any of the parameters have the incorrect data type, I just want to skip that record and move on to the next record. Each call comes from a foreach loop.
The database is reporting the error and PHP is displaying it. I do not have experience with error handling.
Example PHP Code:
foreach($item_array as $item) {
$id = $item['id'];
$color = $item['color'];
$con = connect()
$query = 'EXECUTE PROCEDURE sp_update_db(:id, :color);'
$params = array(':id' => $id, ':color' => $color);
$stmt = prepare($con, $query);
$result = execute($stmt, $params);
close($con);
}
Running the code I get "Warning: SQL error: [stored procedure a paramater was of the incorrect datatype]".