Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. $dbhost = "server";
  2. $dbuser = "test_db";
  3. $dbpass = "test_db";
  4. $dbname = "test";
  5.  
  6. $mysql_conn_string = "mysql:host=$dbhost;dbname=$dbname";
  7.  
  8. try{
  9. $dbConnection = new PDO($mysql_conn_string, $dbuser, $dbpass);
  10. }
  11. catch(PDOException $ex) {
  12.  
  13. echo($ex->getMessage());
  14. }
  15.  
  16. echo(PDO::errorInfo());
  17.  
  18. try {
  19. //connect as appropriate as above
  20. $stmt = $dbConnection->prepare('bogus sql');
  21. } catch(PDOException $ex) {
  22. echo "An Error occured!"; //user friendly message
  23. echo($ex->getMessage());
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement