(isset($persist)) ? $persist : FALSE, //PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING, ); if( ! isset($persist)) { unset($opts[PDO::ATTR_PERSISTENT]); } $options = array_merge($opts, $options); parent::__construct($dsn, $user, $pass, $options); self::$instance[$dbname] =& $this; } // -------------------------------------------------------------------------- /** * PHP magic method to facilitate dynamic methods * * @param string $name * @param array $args */ function __call($name, $args) { if(is_callable($this->$name)) { //Add $this to the beginning of the args array array_unshift($args, $this); //Call the dynamic function return call_user_func_array($this->$name, $args); } } // -------------------------------------------------------------------------- /** * PHP magic methods to call non-static methods statically * * @param string $name * @param array $args */ public static function __callStatic($name, $args) { if(is_callable(parent::$name)) { return call_user_func_array(parent::$name, $args); } } // -------------------------------------------------------------------------- /** * Prints out the contents of the object when used as a string * * @return string */ function __toString() { $args = func_get_args(); $method = ( ! empty($args)) ? $args[0] : "print_r"; $output = '
';
	
		if($method == "var_dump")
		{
			ob_start();
			var_dump($this);
			$output .= ob_get_contents();
			ob_end_clean();
		}
		else if($method == "var_export")
		{
			ob_start();
			var_export($this);
			$output .= ob_get_contents();
			ob_end_clean();
		}	
		else
		{
			$output .= print_r($this, TRUE);
		}
	
		return $output . '
'; } // -------------------------------------------------------------------------- /** * Constructor without the "new" * * @param array $members */ /*function __invoke($db="default") { return self::get_instance($db); } function start_transaction() { if( ! $this->inTransaction()) { return $this->beginTransaction(); } } function commit() { if($this->inTransaction()) { return parent::commit(); } } function rollback() { if($this->inTransaction()) { return parent::rollBack(); } } function prepare($sql, $driver_options=array()) { $this->statement = parent::prepare($sql, $driver_options); return $this->statement; } function set() { }*/ /** * Returns the last error from the database * * @return string */ function get_last_error() { $error = array(); if(isset($this->statement)) { $error = $this->statement->errorInfo(); } else { $error = $this->errorInfo(); } $code = $error[0]; $driver_code = $error[1]; $message = $error[2]; // Contain the content for buffering ob_start(); include(APP_PATH.'/errors/error_db.php'); $buffer = ob_get_contents(); ob_end_clean(); echo $buffer; } } // End of db.php