/** * @desc Returns a default connection (using config data), opens it if needed * @return sql_connection */ public static function get_connection() { if (!empty(self::$default_connection)) { return self::$default_connection; } return self::$default_connection = self::open(); }
public function substitute_params_callback($m) { $cmd = $m[1]; $raw = false; if ($cmd[0] == '!') { $cmd = substr($cmd, 1); $raw = true; } $data = explode('|', $cmd); if (isset($this->params[$data[0]])) { $res = $this->params[$data[0]]; } elseif ($this->_pkg && isset($this->_pkg->config['global_params'][$data[0]])) { $res = $this->_pkg->config['global_params'][$data[0]]; } else { return $m[0]; } // if the variable if (!$raw) { $res = $this->xlink->escape($res); } if (count($data) > 1) { for ($i = 1; isset($data[$i]); $i++) { switch ($data[$i]) { case 'int': $res = intval($res); break; } } } return $res; }
/** * @desc Connect to a mysql using mysqli extention. * $con_config common params and default values: * 'host' => ini_get("mysqli.default_host"), 'port' => ini_get("mysqli.default_port"), * 'user' => ini_get("mysqli.default_user"), 'pass' => ini_get("mysqli.default_pw"), * 'db' => '', * if $con_config['link'] is set to mysqli object, do not open new connection * just wrap already open mysqli connection with this class * @param $con_config - connection config */ public function __construct($con_config) { parent::__construct(); $pkg = pkgman_manager::getp("sql"); $default_config = array('host' => ini_get("mysqli.default_host"), 'port' => ini_get("mysqli.default_port"), 'user' => ini_get("mysqli.default_user"), 'pass' => ini_get("mysqli.default_pw"), 'db' => '', 'socket' => ini_get("mysqli.default_socket"), 'charset' => @$pkg->config['charset'], 'buffered' => true, 'throw_on_error' => @$pkg->config['throw_on_error'], 'on_demand' => false); // merge all config arrays together if (empty($con_config)) { $con_config = array(); } $this->config = array_merge($this->config, $default_config, $con_config); if (empty($this->config['on_demand'])) { $this->set_link(); } }