AAD Web Team Posted October 28 Share Posted October 28 Is it possible to connect to a non-ProcessWire database using WireDatabasePDO, and have error handling, so if the database is unavailable then the page can recover gracefully? I tried: try { $db = new WireDatabasePDO([ /* dsn, user, pass */ ]); } catch (\Exception $e) { /* Code to handle the problem gracefully */ } This doesn’t work – it seems that the exception is dealt with by ProcessWire before my code sees it. Is it better just to use PHP’s native PDO object directly? Something such as: try { $dbh = new \PDO($dsn, $user, $password); } catch (\PDOException $e) { /* Code to handle the problem */ } Link to comment Share on other sites More sharing options...
BitPoet Posted October 28 Share Posted October 28 WireDatabasePDO's constructur doesn't connect to the database yet. This is either implicitly done when the query or exec(ute) methods are called, or explicitly by invoking $db->pdo(), which will return the underlying plain PDO object. 2 Link to comment Share on other sites More sharing options...
AAD Web Team Posted October 29 Author Share Posted October 29 Great, thanks! I put the try/catch around the $db->query() method rather new WireDatabasePDO constructor and it worked well. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now