Guest User

Untitled

a guest
May 18th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <?php
  2. // Connect to a database named "mary"
  3. $dbconn = pg_connect("dbname=mary");
  4.  
  5. // Prepare a query for execution
  6. $result = pg_prepare($dbconn, "my_query", 'SELECT * FROM shops WHERE name = $1');
  7.  
  8. // Execute the prepared query. Note that it is not necessary to escape
  9. // the string "Joe's Widgets" in any way
  10. $result = pg_execute($dbconn, "my_query", array("Joe's Widgets"));
  11.  
  12. // Execute the same prepared query, this time with a different parameter
  13. $result = pg_execute($dbconn, "my_query", array("Clothes Clothes Clothes"));
  14. ?>
  15.  
  16. <?php
  17. $pdo = new PDO('pgsql:dbname=example;user=me;password=pass;host=localhost;port=5432');
  18.  
  19. $sql = "SELECT username, password
  20. FROM users
  21. WHERE username = :username
  22. AND password = :pass";
  23.  
  24. $sth = $pdo->prepare($sql);
  25. $sth->execute(array(':username' => $_POST['username'], ':pass' => $_POST['password']));
  26. $result = $sth->fetchAll();
  27.  
  28. <?php
  29. $pdo = new PDO('pgsql:dbname=example;user=me;password=pass;host=localhost;port=5432');
  30.  
  31. $sql = "SELECT username, password
  32. FROM users
  33. WHERE username = ?
  34. AND password = ?";
  35.  
  36. $sth = $pdo->prepare($sql);
  37. $sth->execute(array($_POST['username'], $_POST['password']));
  38. $result = $sth->fetchAll();
  39.  
  40. $result = pg_prepare($dbconn, "my_query", 'SELECT * FROM shops WHERE name = $1');
  41. $result = pg_execute($dbconn, "my_query", array("Joe's Widgets"));
  42. $result = pg_execute($dbconn, "my_query", array("row two"));
  43. $result = pg_execute($dbconn, "my_query", array("row three"));
  44.  
  45. $result = pg_prepare($dbconn, "query1", 'SELECT passhash_md5 FROM users WHERE email = $1');
  46.  
  47. $result = pg_prepare($dbconn, "query1", 'SELECT passhash_md5 FROM users WHERE email = ?');
Add Comment
Please, Sign In to add comment