Welcome Guest, Not a member yet? Register   Sign In
Catch exeption from database insert
#11

I have this piece of code:

PHP Code:
use CodeIgniter\Database\Exceptions\DataException;
try {
 
log_message('debug''-- tx begin --');
 
$this->db->transBegin();
 
$rc $this->finalize($par);
 
log_message('debug''-- tx commit --');
 
$this->db->transCommit();
 return 
$rc;
 } 
 catch(\
DatabaseException $e)
 {
 
log_message('error''SQL Exception: ' $e->getMessage()); 
 
log_message('debug''-- tx rollback --');
 
$this->db->transRollback();
 
cache()->delete('character-'.session()->get('character_id'));
 
session()->setFlashdata('error''An Exception occured while saving data, please alert administration.');
 return 
false;
 } 

The statements throws a mysql_exception, but the code doesn't catch the DatabaseException... why? (DDdebug is true)

ERROR - 2024-08-20 17:31:02 --> mysqli_sql_exception: Cannot delete or update a parent row: a foreign key constraint fails (`chronicles_fix`.`structure_units`, CONSTRAINT `FK_structure_units_structures` FOREIGN KEY (`structure_id`) REFERENCES `structures` (`id`)) in C:\laragon-6.0.0\www\chronicles_fix\system\Database\MySQLi\Connection.php:306
Stack trace:
#0 C:\laragon-6.0.0\www\chronicles_fix\system\Database\MySQLi\Connection.php(306): mysqli->query('DELETE FROM `st...', 0)
#1 C:\laragon-6.0.0\www\chronicles_fix\system\Database\BaseConnection.php(692): CodeIgniter\Database\MySQLi\Connection->execute('DELETE FROM `st...')
#2 C:\laragon-6.0.0\www\chronicles_fix\system\Database\BaseConnection.php(606): CodeIgniter\Database\BaseConnection->simpleQuery('DELETE FROM `st...')
#3 C:\laragon-6.0.0\www\chronicles_fix\system\Database\BaseBuilder.php(2791): CodeIgniter\Database\BaseConnection->query('DELETE FROM `st...', Array, false)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB