| | |
| | | function dsn_connect($dsn) |
| | | { |
| | | // Use persistent connections if available |
| | | $dbh = MDB2::factory($dsn, array('persistent' => TRUE)); |
| | | $dbh = MDB2::factory($dsn, array('persistent' => $true)); |
| | | |
| | | if (PEAR::isError($dbh)) |
| | | raise_error(array('code' => 500, |
| | |
| | | // Query database |
| | | |
| | | function query() |
| | | |
| | | { |
| | | |
| | | $params = func_get_args(); |
| | | |
| | | $query = array_shift($params); |
| | | |
| | | |
| | | |
| | | return $this->_query($query, 0, 0, $params); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | function limitquery() |
| | | |
| | | { |
| | | |
| | | $params = func_get_args(); |
| | | |
| | | $query = array_shift($params); |
| | | |
| | | $offset = array_shift($params); |
| | | |
| | | $numrows = array_shift($params); |
| | | |
| | | |
| | | |
| | | return $this->_query($query, $offset, $numrows, $params); |
| | | |
| | | } |
| | | |
| | | function _query($query, $offset, $numrows, $params) |
| | |
| | | $this->db_handle->row_offset = $offset; |
| | | $this->db_handle->row_limit = $numrows; |
| | | |
| | | $result = $this->db_handle->query($query); |
| | | $result = $this->db_handle->query($query,$params); |
| | | |
| | | if (PEAR::isError($result)) |
| | | raise_error(array('code' => 500, |
| | |
| | | } |
| | | |
| | | function quoteIdentifier ( $str ) |
| | | |
| | | { |
| | | |
| | | if (!$this->db_handle) |
| | | |
| | | $this->db_connect('r'); |
| | | |
| | | |
| | | |
| | | return $this->db_handle->quoteIdentifier($str); |
| | | |
| | | } |
| | | |
| | | function unixtimestamp($field) |
| | | |
| | | { |
| | | |
| | | switch($this->db_provider) |
| | | |
| | | { |
| | | |
| | | case 'pgsql': |
| | | |
| | | return "EXTRACT (EPOCH FROM $field)"; |
| | | |
| | | break; |
| | | |
| | | default: |
| | | |
| | | return "UNIX_TIMESTAMP($field)"; |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | function _add_result($res, $query) |