Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $jobnumber = db_quick($sql);
- db_query($sql);
- //initializes MySQL connection object in the global scope
- $dblink = MySqlConnector::getMySql();
- function db_query($sql)
- {
- //previously initialized MySQL connection object
- global $dblink;
- //native MySQL API call:
- return mysqli_query($dblink, $sql);
- }
- //in a calling class:
- $repository = new GenericRepository();
- $repository->getMySql()->persist($sql);
- $value = $repository->getMySql()->paramQuery($sql, $param);
- //GenericRepository makes a static call to the actual connector
- class GenericRepository
- {
- final public function getMySql()
- {
- if ($this->link === null)
- $this->link = MySqlConnector::getMySql();
- return $this->link;
- }
- }
- //Connector calls MySQL API
- class MySqlConnector
- {
- public static function getMySql()
- {
- if (null === static::$instance)
- {
- include 'include/config.php';
- //class MySql extends mysqli library
- static::$instance = new MySql(DBHOST, DBUSER, DBPASS);
- }
- return static::$instance;
- }
- }
- db_query($sql);
- (new NamespaceGenericRepository())->getMySql()->persist($sql);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement