Advertisement
Guest User

Untitled

a guest
May 13th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. ##### creating a connection variable in connect.php ####
  2. require_once('/../../../connection_info.php');
  3.  
  4. $db_host = 'localhost';
  5. $db_user = 'root';
  6. $db_pass = 'somePaSSWoRd';
  7. $db_name = 'database_name';
  8. try
  9. {
  10. $pdo = new PDO('mysql:host=' . $db_host . ';' . 'dbname=' . $db_name . ';' . 'charset=utf8',$db_user,$db_pass);
  11. }
  12. catch (PDOException $e)
  13. {
  14. echo $e->getMessage();
  15. }
  16.  
  17.  
  18. #### typical use in someFile.php ####
  19.  
  20. require_once('../connect.php');
  21.  
  22.  
  23. function get_book_details($input, $pdo){
  24. $username= $input['username'];
  25. $password = $input['password'];
  26.  
  27. try{
  28. $q = $pdo->prepare("SELECT * FROM users WHERE user = :user AND pass = :pass");
  29. $q->bindValue(":user", $username);
  30. $q->bindValue(":user", $username);
  31.  
  32. $q->execute();
  33. } catch (PDOException $e){
  34. echo $e->getMessage();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement