Guest User

Untitled

a guest
Jun 21st, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. <?
  2. $dsn = 'mysql:dbname=test;host=hostname';
  3. $user = 'username';
  4. $password = 'Password';
  5. try {
  6. $dbh = new PDO($dsn, $user, $password);
  7. echo "Connected";
  8. } catch (PDOException $e) {
  9. echo 'Connection failed: ' . $e->getMessage();
  10. }
  11.  
  12. $id = 1;
  13. $sth = $dbh->prepare("SELECT * FROM testprepare where id = :id");
  14. $sth->bindParam(':id',$id, PDO::PARAM_INT);
  15. $sth->execute();
  16. $result = $sth->fetchAll();
  17.  
  18. print_r($result);
  19.  
  20. ?>
Add Comment
Please, Sign In to add comment