October 4, 20169 yr Hello, it;s been a while. I wonder if someone can help.I have some code. I'm attempting to connect to a database via SQLite. Actually the database always connects. I'm trying to trigger an exception in a try catch blog but no matter what I do (deliberately mispelling the database name) to trigger the exception, the connection message will always show up.Here's my code. <?php try { $db = new PDO("sqlite:" . __DIR__ . "/database.db"); var_dump($db); } catch (Exception $e) { echo "Unable to connect to the database"; exit; } echo "Connected to the database successfully"; ?> So what happens is instead of blocking the connection if I use a different name it will create a new empty file of that name. http://www.jonniegrieve.co.uk/jg-lab.co.uk/medlib-sql/inc/connection.php The code is sound. Is there some reason the code is doing this that I should know of? Thanks Edited October 4, 20169 yr by webDesignerJon
October 5, 20169 yr Author Thanks for your reply But why wouldn't it output the copy of the database then? Why an empty file of the incorrect filename? I should clarify the filename in the code is actually the correct one. I should have posted an incorrect one. In which case surely an exception should then be triggered? I have seen one instance in another server location where an incorrect file name triggers an exception, no connection to the database. However this is not the case on localhost or my own web server. Thanks. :-)
Create an account or sign in to comment