cabbie Posted April 3, 2013 Share Posted April 3, 2013 Why doesnt this error print out? (Delect) <?php try { $DBH = new PDO("mysql:host=localhost;dbname=libertc0_lr", 'libertc0_vadmin', '*****'); $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $DBH->prepare('DELECT name FROM people'); } catch(PDOException $e) { echo "I'm sorry, Dave. I'm afraid I can't do that."; file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/276486-db-errors/ Share on other sites More sharing options...
waynew Posted April 3, 2013 Share Posted April 3, 2013 (edited) This is happening because by default, PDO emulates prepared statements with sprintf. This means that you're not actually communication with the database server when you prepare your statement. Thus, the statement cannot be validated. This will work because I've changed the PDO::ATTR_EMULATE_PREPARES attribute to FALSE: <?php try { $DBH = new PDO("mysql:host=localhost;dbname=libertc0_lr", 'libertc0_vadmin', '*****'); $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $DBH->setAttribute( PDO::ATTR_EMULATE_PREPARES, false ); $DBH->prepare('DELECT name FROM people'); } catch(PDOException $e) { echo "I'm sorry, Dave. I'm afraid I can't do that."; file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND); } Edited April 3, 2013 by waynewex Quote Link to comment https://forums.phpfreaks.com/topic/276486-db-errors/#findComment-1422661 Share on other sites More sharing options...
Solution cabbie Posted April 3, 2013 Author Solution Share Posted April 3, 2013 (edited) OK THnx.. Edited April 3, 2013 by cabbie Quote Link to comment https://forums.phpfreaks.com/topic/276486-db-errors/#findComment-1422670 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.