Last active
August 29, 2015 13:56
-
-
Save werring/9262114 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 | |
| namespace Model; | |
| use Base\Exceptions\DatabaseConnect; | |
| use Base\Log; | |
| class Database extends Main { | |
| private static $instances = array(); | |
| /** | |
| * @var \mysqli | |
| */ | |
| protected $db = null; | |
| protected $lastQuery=""; | |
| /** | |
| * @param string $name | |
| * @return Database | |
| */ | |
| public static function getInstance($name="default"){ | |
| if(!isset(self::$instances[$name])) self::$instances[$name] = new Database(); | |
| return self::$instances[$name]; | |
| } | |
| protected function init(){ | |
| $this->db = new \mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS ,MYSQL_DABA); | |
| if(!is_null($this->db->connect_error)){ | |
| Log::fatal($this->db->connect_error); | |
| throw new DatabaseConnect($this->db->connect_error,$this->db->connect_errno); | |
| } | |
| } | |
| public function query($q){ | |
| $prepared = $this->db->prepare("SELECT name FROM tmp"); | |
| $prepared->execute(); | |
| var_dump($prepared); | |
| return $prepared; | |
| } | |
| } |
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
| bool(true) | |
| object(mysqli_stmt)#3 (9) { | |
| ["affected_rows"]=> | |
| int(-1) | |
| ["insert_id"]=> | |
| int(0) | |
| ["num_rows"]=> | |
| int(0) | |
| ["param_count"]=> | |
| int(0) | |
| ["field_count"]=> | |
| int(1) | |
| ["errno"]=> | |
| int(0) | |
| ["error"]=> | |
| string(0) "" | |
| ["sqlstate"]=> | |
| string(5) "00000" | |
| ["id"]=> | |
| int(1) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment