Jump to content

db errors


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);  

}  
 
Link to comment
https://forums.phpfreaks.com/topic/276486-db-errors/#findComment-1422661
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.