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); } ?> 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 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); } Link to comment https://forums.phpfreaks.com/topic/276486-db-errors/#findComment-1422661 Share on other sites More sharing options...
cabbie Posted April 3, 2013 Author Share Posted April 3, 2013 OK THnx.. Link to comment https://forums.phpfreaks.com/topic/276486-db-errors/#findComment-1422670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.