Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. <?php
  2.  
  3. echo "Hello!";
  4.  
  5. class Database {
  6.  
  7. private static $link = null;
  8.  
  9. private static function getLink() {
  10.  
  11. if (self::$link) {
  12. return self::$link;
  13. }
  14.  
  15. $ini = _BASE_DIR . "config.ini";
  16. $parse = parse_ini_file ($ini, true);
  17.  
  18. $driver = $parse["db_driver"];
  19. $dsn = "${driver}:";
  20. $user = $parse["db_user"];
  21. $password = $parse["db_password"];
  22.  
  23.  
  24. foreach ($parse["dsn"] as $k => $v) {
  25. $dsn .= "${k}=${v};";
  26. }
  27.  
  28. $link = new PDO($dsn,$user,$password);
  29.  
  30. return self::$link;
  31.  
  32. }
  33.  
  34. }
  35.  
  36. echo "End of class";
  37.  
  38. $stmt = Database :: prepare ("INSERT INTO cities (city_name, location_x, location_y) VALUES ('London', 0, 0);");
  39. echo "Prepared!";
  40. $stmt -> execute();
  41. echo "Executed!";
  42. var_dump($stmt -> fetchAll());
  43. $stmt -> closeCursor();
  44.  
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement