Advertisement
gundambison

contoh pdo user

Feb 18th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 KB | None | 0 0
  1. <?php
  2. $dsn = 'mysql:dbname=testdb;host=127.0.0.1';
  3. $user = 'dbuser';
  4. $password = 'dbpass';
  5.  
  6. try
  7. {
  8.     $conn = new PDO($dsn, $user, $password);
  9. }
  10. catch(PDOException $e)
  11. {
  12.     echo 'Connection failed: ' . $e->getMessage();
  13. }
  14.  
  15. $sql = "select * from user where username like ?";
  16. $stmt = $dbh->prepare($sql);
  17. $stmt->execute(array(
  18.     $user
  19. ));
  20. if (!$stmt)
  21. {
  22.     echo "\nPDO::errorInfo():\n";
  23.     print_r($conn->errorInfo());
  24. }
  25. else
  26. {
  27.     $userku = $stmt->fetchAll();
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement