Guest User

Untitled

a guest
Nov 17th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. class Database {
  2.  
  3. private static $link = null;
  4.  
  5. private static function getLink() {
  6. if (self::$link) {
  7. return self::$link;
  8. }
  9.  
  10. $ini = "/home/world/private/mmn_mvsoftware.ini";
  11. $parse = parse_ini_file($ini, true);
  12.  
  13. $driver = $parse ["db_driver"];
  14. $dsn = "${driver}:";
  15. $user = $parse ["db_user"];
  16. $password = $parse ["db_password"];
  17. $options = $parse ["db_options"];
  18. $attributes = $parse ["db_attributes"];
  19.  
  20. foreach ($parse ["dsn"] as $k => $v) {
  21. $dsn .= "${k}=${v};";
  22. }
  23.  
  24. self::$link = new PDO($dsn, $user, $password, $options);
  25. self::$link->Exec("SET AUTOCOMMIT=0");
  26. self::$link->Exec("SET CHARACTER SET utf8");
  27.  
  28. foreach ($attributes as $k => $v) {
  29. self::$link->setAttribute(constant("PDO::{$k}"), constant("PDO::{$v}"));
  30. }
  31.  
  32. self::$link->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
  33.  
  34. return self::$link;
  35. }
  36.  
  37. public static function __callStatic($name, $args) {
  38. $callback = array(
  39. self::getLink(),
  40. $name
  41. );
  42.  
  43. $res = call_user_func_array($callback, $args);
  44.  
  45.  
  46.  
  47. return $res;
  48. }
  49.  
  50. }
  51.  
  52. $Query = Database::Prepare("SELECT CURRENT_DATE AS DATA_SYS, CURRENT_TIME AS HORA_SYS");
  53. $Query->Execute();
Add Comment
Please, Sign In to add comment