Welcome Guest, Not a member yet? Register   Sign In
Fatal Errors when DataBase command fails
#1

Hello all, I'm having a struggle with Fatal Errors being thrown when some of my Databases commands don't return successfully, for example:

Code:
$flag = true;
$db = \Config\Database::connect();
$builder_audio = $db->table('audios');

$data = [
'name' => $name,
'path' => $path
];

$builder_audio->insert($data);

if(!$db->affectedRows()){
$flag = false;
return $flag;
}

return $flag;

In my Database (Postgres) I created an UNIQUE KEY for the column "name". So when I try to insert a name that already exists I would like to get a return of none "affectedRows", and then deal with this return in my function, but when the error occurs, I get a Fatal Error, my request returns instantly with code 500 and an error description that follows:

Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse json string, error: "Type is not supported". in /var/www/html/mysite/system/Format/Exceptions/FormatException.php:9

I could create an SELECT to search for the name before the INSERT, but I'm planning in creating some control in my database using UNIQUE KEYS for a better setup.

Thanks in advance
Reply


Messages In This Thread
Fatal Errors when DataBase command fails - by GuilhermeBiz - 10-18-2019, 07:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB