Created
August 25, 2011 21:09
-
-
Save anonymous/1171965 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Class Mysql extends mysqli{ | |
public function __construct($registry){ | |
// define registry property | |
$this->registry = $registry; | |
// initialize parent constructor | |
parent::__construct($this->registry->config->database->hostname, $this->registry->config->database->username, $this->registry->config->database->password, $this->registry->config->database->database); | |
} | |
public function query(){ | |
// define $arguments | |
$arguments = func_get_args(); | |
// define $argumentCount | |
$argumentCount = count($arguments); | |
switch($argumentCount){ | |
case 1: | |
$sql = $this->escape_string($arguments[0]); | |
break; | |
default: | |
$sql = vsprintf($arguments[0], array_map(array($this, 'escape_string'), array_slice($arguments, 1))); | |
break; | |
} | |
// log queries | |
$this->registry->logger->log($sql); | |
// return query result | |
return parent::query($sql); | |
} | |
// overload properties to allow for database name toggles, i.e. $this->databaseName->query | |
public function __get($database){ | |
// select database | |
$this->select_db($database); | |
// return self instance | |
return $this; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment