Catching exception from db exec function

64 views
Skip to first unread message

Sebastien

unread,
Aug 25, 2017, 6:14:04 PM8/25/17
to Fat-Free Framework
Hi,

The exec function should return false if an error occurs, but in my case, it generates an exception.


Code:
$results = $this->db->exec($sqlcommand);

$sqlcommand comes from an admin page from my CMS used to run sql queries or commands.

I'm running on f3 3.5 and I'm using sqlite.

I also tried to catch the PDOException without success.

Thanks

ved

unread,
Aug 30, 2017, 7:52:55 AM8/30/17
to Fat-Free Framework
Try and use the options parameter on the constructor as documented here.

Setting the following option:

$options = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION];
$db
= new \DB\SQL('mysql:host=localhost;port=3306;dbname=mysqldb','username','password', $options);

This should allow you to catch the PDOExceptions.

Sebastien

unread,
Aug 30, 2017, 12:06:12 PM8/30/17
to Fat-Free Framework
That's what I'm doing

$db=new \DB\SQL(
$f3->get('db'),
$f3->get('dbuser'),
$f3->get('dbpasss'),
array( \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION)
);

ved

unread,
Aug 30, 2017, 1:23:04 PM8/30/17
to Fat-Free Framework
Can you please try with the latest F3 version from https://github.com/bcosca/fatfree-core

v3.5 is a bit dated and a lot of fixes and improvements have been done since so maybe it's something that's been fixed since.

I personally use the sql mapper with mysql/mariadb and I can catch PDO's exceptions.
Reply all
Reply to author
Forward
0 new messages