Jump to content

db errors


Go to solution Solved by cabbie,

Recommended Posts

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

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 by waynewex
Link to comment
https://forums.phpfreaks.com/topic/276486-db-errors/#findComment-1422661
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.