Advertisement
Guest User

Untitled

a guest
Jun 8th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. <?php
  2.  
  3. $host = "localhost";
  4. $db = "dev";
  5. $user = "dev";
  6. $pass = "dev";
  7. $dsn = "mysql:host=$host;dbname=$db;";
  8.  
  9. try
  10. {
  11. $pdo = new PDO($dsn, $user, $pass);
  12. } catch (PDOException $ex) {
  13. echo 'Connection failed: ' . $ex->getMessage();
  14. die();
  15. }
  16.  
  17. ?>
  18.  
  19. <?php
  20.  
  21. include_once('pdo.inc.php');
  22.  
  23. class Customers
  24. {
  25. function GetCustomerName($pdo, $customer_id)
  26. {
  27. $query = "SELECT first_name FROM Customers WHERE customer_id = :customer_id LIMIT 1";
  28. $stmt = $pdo->prepare($query);
  29. $stmt->bindParam(':customer_id', $customer_id);
  30. $stmt->execute();
  31. return $stmt->fetchColumn();
  32. }
  33. }
  34.  
  35. ?>
  36.  
  37. <?php
  38.  
  39. include_once('customers.class.php');
  40.  
  41. $a = new Customers();
  42.  
  43. echo $a->GetCustomerName($pdo, 1);
  44.  
  45. ?>
  46.  
  47. function GetCustomerName(PDO $pdo, int $customer_id) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement