| | |
| | | <?php |
| | | |
| | | /* |
| | | /** |
| | | +-----------------------------------------------------------------------+ |
| | | | program/include/rcube_db.php | |
| | | | | |
| | |
| | | protected $conn_failure = false; |
| | | protected $a_query_results = array('dummy'); |
| | | protected $last_res_id = 0; |
| | | protected $db_index = 0; |
| | | protected $tables; |
| | | protected $variables; |
| | | protected $db_index = 0; |
| | | |
| | | protected $options = array( |
| | | // column/table quotes |
| | |
| | | /** |
| | | * Getter for error state |
| | | * |
| | | * @param boolean True on error |
| | | * @return boolean True on error |
| | | */ |
| | | public function is_error() |
| | | { |
| | |
| | | /** |
| | | * Connection state checker |
| | | * |
| | | * @param boolean True if in connected state |
| | | * @return boolean True if in connected state |
| | | */ |
| | | public function is_connected() |
| | | { |
| | |
| | | |
| | | /** |
| | | * Is database replication configured? |
| | | * This returns true if dsnw != dsnr |
| | | * |
| | | * @return bool Returns true if dsnw != dsnr |
| | | */ |
| | | public function is_replicated() |
| | | { |
| | |
| | | * Execute a SQL query with limits |
| | | * |
| | | * @param string SQL query to execute |
| | | * @param number Offset for LIMIT statement |
| | | * @param number Number of rows for LIMIT statement |
| | | * @param int Offset for LIMIT statement |
| | | * @param int Number of rows for LIMIT statement |
| | | * @param mixed Values to be inserted in query |
| | | * |
| | | * @return number Query handle identifier |
| | | * @return int Query handle identifier |
| | | */ |
| | | public function limitquery() |
| | | { |
| | |
| | | * Execute a SQL query with limits |
| | | * |
| | | * @param string $query SQL query to execute |
| | | * @param number $offset Offset for LIMIT statement |
| | | * @param number $numrows Number of rows for LIMIT statement |
| | | * @param int $offset Offset for LIMIT statement |
| | | * @param int $numrows Number of rows for LIMIT statement |
| | | * @param array $params Values to be inserted in query |
| | | * @return number Query handle identifier |
| | | * |
| | | * @return int Query handle identifier |
| | | */ |
| | | protected function _query($query, $offset, $numrows, $params) |
| | | { |
| | |
| | | * Get number of affected rows for the last query |
| | | * |
| | | * @param number $res_id Optional query handle identifier |
| | | * @return mixed Number of rows or false on failure |
| | | * |
| | | * @return int Number of rows or false on failure |
| | | */ |
| | | public function affected_rows($res_id = null) |
| | | { |
| | |
| | | * Get an associative array for one row |
| | | * If no query handle is specified, the last query will be taken as reference |
| | | * |
| | | * @param number $res_id Optional query handle identifier |
| | | * @param int $res_id Optional query handle identifier |
| | | * |
| | | * @return mixed Array with col values or false on failure |
| | | */ |
| | |
| | | * Get an index array for one row |
| | | * If no query handle is specified, the last query will be taken as reference |
| | | * |
| | | * @param number $res_id Optional query handle identifier |
| | | * @param int $res_id Optional query handle identifier |
| | | * |
| | | * @return mixed Array with col values or false on failure |
| | | */ |
| | |
| | | * Get col values for a result row |
| | | * |
| | | * @param PDOStatement $result Result handle |
| | | * @param number $mode Fetch mode identifier |
| | | * @param int $mode Fetch mode identifier |
| | | * |
| | | * @return mixed Array with col values or false on failure |
| | | */ |
| | |
| | | /** |
| | | * Returns list of columns in database table |
| | | * |
| | | * @param string Table name |
| | | * @param string $table Table name |
| | | * |
| | | * @return array List of table cols |
| | | */ |
| | |
| | | /** |
| | | * Return SQL statement to convert from a unix timestamp |
| | | * |
| | | * @param string $timestamp Field name |
| | | * @param int $timestamp Unix timestamp |
| | | * |
| | | * @return string SQL statement to use in query |
| | | * @return string Date string in db-specific format |
| | | */ |
| | | public function fromunixtime($timestamp) |
| | | { |
| | |
| | | * |
| | | * @param object $res Query handle |
| | | * |
| | | * @return mixed Handle ID |
| | | * @return int Handle ID |
| | | */ |
| | | protected function _add_result($res) |
| | | { |
| | | $res_id = sizeof($this->a_query_results); |
| | | $this->last_res_id = $res_id; |
| | | $this->a_query_results[$res_id] = $res; |
| | | $this->last_res_id = sizeof($this->a_query_results); |
| | | $this->a_query_results[$this->last_res_id] = $res; |
| | | |
| | | return $res_id; |
| | | return $this->last_res_id; |
| | | } |
| | | |
| | | /** |
| | | * Resolves a given handle ID and returns the according query handle |
| | | * If no ID is specified, the last resource handle will be returned |
| | | * |
| | | * @param number $res_id Handle ID |
| | | * @param int $res_id Handle ID |
| | | * |
| | | * @return mixed Resource handle or false on failure |
| | | */ |
| | |
| | | if (($pos = strpos($dsn, '://')) !== false) { |
| | | $str = substr($dsn, 0, $pos); |
| | | $dsn = substr($dsn, $pos + 3); |
| | | } else { |
| | | } |
| | | else { |
| | | $str = $dsn; |
| | | $dsn = null; |
| | | } |
| | |
| | | if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) { |
| | | $parsed['phptype'] = $arr[1]; |
| | | $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2]; |
| | | } else { |
| | | } |
| | | else { |
| | | $parsed['phptype'] = $str; |
| | | $parsed['dbsyntax'] = $str; |
| | | } |
| | |
| | | if (($pos = strpos($str, ':')) !== false) { |
| | | $parsed['username'] = rawurldecode(substr($str, 0, $pos)); |
| | | $parsed['password'] = rawurldecode(substr($str, $pos + 1)); |
| | | } else { |
| | | } |
| | | else { |
| | | $parsed['username'] = rawurldecode($str); |
| | | } |
| | | } |
| | |
| | | $pos = strrpos($proto_opts, '/'); |
| | | $dsn = substr($proto_opts, $pos + 1); |
| | | $proto_opts = substr($proto_opts, 0, $pos); |
| | | } elseif (strpos($dsn, '/') !== false) { |
| | | } |
| | | else if (strpos($dsn, '/') !== false) { |
| | | list($proto_opts, $dsn) = explode('/', $dsn, 2); |
| | | } else { |
| | | } |
| | | else { |
| | | $proto_opts = $dsn; |
| | | $dsn = null; |
| | | } |
| | |
| | | $dsn = substr($dsn, $pos + 1); |
| | | if (strpos($dsn, '&') !== false) { |
| | | $opts = explode('&', $dsn); |
| | | } else { // database?param1=value1 |
| | | } |
| | | else { // database?param1=value1 |
| | | $opts = array($dsn); |
| | | } |
| | | foreach ($opts as $opt) { |