Advertisement
Guest User

Untitled

a guest
Dec 27th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. $jobnumber = db_quick($sql);
  2. db_query($sql);
  3.  
  4. //initializes MySQL connection object in the global scope
  5. $dblink = MySqlConnector::getMySql();
  6.  
  7. function db_query($sql)
  8. {
  9. //previously initialized MySQL connection object
  10. global $dblink;
  11.  
  12. //native MySQL API call:
  13. return mysqli_query($dblink, $sql);
  14. }
  15.  
  16. //in a calling class:
  17. $repository = new GenericRepository();
  18. $repository->getMySql()->persist($sql);
  19. $value = $repository->getMySql()->paramQuery($sql, $param);
  20.  
  21. //GenericRepository makes a static call to the actual connector
  22. class GenericRepository
  23. {
  24. final public function getMySql()
  25. {
  26. if ($this->link === null)
  27. $this->link = MySqlConnector::getMySql();
  28.  
  29. return $this->link;
  30. }
  31. }
  32.  
  33. //Connector calls MySQL API
  34. class MySqlConnector
  35. {
  36.  
  37. public static function getMySql()
  38. {
  39. if (null === static::$instance)
  40. {
  41. include 'include/config.php';
  42.  
  43. //class MySql extends mysqli library
  44. static::$instance = new MySql(DBHOST, DBUSER, DBPASS);
  45. }
  46.  
  47. return static::$instance;
  48. }
  49. }
  50.  
  51. db_query($sql);
  52.  
  53. (new NamespaceGenericRepository())->getMySql()->persist($sql);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement