× close ? help v save end of line: Text editor: /wanples.com/oc-includes/osclass/classes/database/DBCommandClass.php connId = &$connId; $this->resultId = 0; $this->queries = array(); $this->queryTimes = array(); $this->queryCount = 0; $this->errorLevel = 0; $this->errorDesc = ""; $this->aSelect = array(); $this->aFrom = array(); $this->aJoin = array(); $this->aWhere = array(); $this->aLike = array(); $this->aGroupby = array(); $this->aHaving = array(); $this->aLimit = false; $this->aOffset = false; $this->aOrder = false; $this->aOrderby = array(); $this->aWherein = array(); if ( OSC_DEBUG_DB || OSC_DEBUG_DB_EXPLAIN ) $this->log = LogDatabase::newInstance(); } /** * Unset connection and result objects */ function __destruct() { unset($this->connId); unset($this->resultId); } /** * It creates a new DBCommandClass object or if it has been created before, it * returns the previous object * * @access public * @since 2.3 * @return DBCommandClass */ public static function newInstance() { if(!self::$instance instanceof self) { self::$instance = new self; } return self::$instance; } /** * Set SELECT clause * * @access public * @since 2.3 * @param mixed $select It can be a string or array * @return DBCommandClass */ function select($select = '*') { if( is_string($select) ) { $select = explode(',', $select); } foreach($select as $s) { $s = trim($s); if($s != '') { $this->aSelect[] = $s; } } return $this; } /** * Set FROM clause * * @param mixed $from It can be a string or array * @return DBCommandClass */ function from($from) { if( !is_array($from) ) { if( strpos($from, ',') !== false) { $from = explode(',', $from); } else { $from = array($from); } } foreach($from as $f) { $this->aFrom[] = $f; } return $this; } /** * Set JOIN clause * * @access public * @since 2.3 * @param string $table * @param string $cond * @param string $type It can be: LEFT, RIGHT, OUTER, INNER, LEFT OUTER or RIGHT OUTER * @return DBCommandClass */ function join($table, $cond, $type = '') { if($type != '') { $type = strtoupper(trim($type)); if( !in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER')) ) { $type = ''; } else { $type .= ' '; } } $join = $type . ' JOIN ' . $table . ' ON ' . $cond; $this->aJoin[] = $join; return $this; } /** * Set WHERE clause using OR operator * * @access public * @since 2.3 * @param mixed $key * @param mixed $value * @return DBCommandClass */ function where($key, $value = null) { return $this->_where($key, $value, 'AND '); } /** * Set WHERE clause using OR operator * * @access public * @since 2.3 * @param mixed $key * @param mixed $value * @return DBCommandClass */ function orWhere($key, $value = null) { return $this->_where($key, $value, 'OR '); } /** * Set WHERE clause * * @access private * @since 2.3 * @param mixed $key * @param mixed $value * @param string $type * @return DBCommandClass */ function _where($key, $value = null, $type = 'AND ') { if( !is_array($key) ) { $key = array($key => $value); } foreach($key as $k => $v) { $prefix = (count($this->aWhere) > 0) ? $type : ''; if( !$this->_hasOperator($k) ) { $k .= ' ='; } if(!is_null($v)) { $v = ' ' . $this->escape($v); } $this->aWhere[] = $prefix . $k . $v; } return $this; } /** * Set WHERE IN clause using AND operator * * @access public * @since 2.3 * @param mixed $key * @param mixed $values * @return DBCommandClass */ function whereIn($key = null, $values = null) { return $this->_whereIn($key, $values, false, 'AND '); } /** * Set WHERE IN clause using OR operator * * @access public * @since 2.3 * @param mixed $key * @param mixed $values * @return DBCommandClass */ function orWhereIn($key = null, $values = null) { return $this->_whereIn($key, $values, false, 'OR '); } /** * Set WHERE NOT IN clause using AND operator * * @access public * @since 2.3 * @param mixed $key * @param mixed $values * @return DBCommandClass */ function whereNotIn($key = null, $values = null) { return $this->_whereIn($key, $values, true, 'AND '); } /** * Set WHERE NOT IN clause using OR operator * * @access public * @since 2.3 * @param mixed $key * @param mixed $values * @return DBCommandClass */ function orWhereNotIn($key = null, $values = null) { return $this->_whereIn($key, $values, true, 'OR '); } /** * Set WHERE IN clause * * @access private * @since 2.3 * @param mixed $key * @param mixed $values * @param bool $not * @param string $type * @return DBCommandClass */ function _whereIn($key = null, $values = null, $not = false, $type = 'AND ') { if( !is_array($values) ) { $values = array($values); } $not = ($not) ? ' NOT' : ''; foreach($values as $value) { $this->aWherein[] = $this->escape($value); } $prefix = (count($this->aWhere) > 0) ? $type : ''; $whereIn = $prefix . $key . $not . ' IN (' . implode(', ', $this->aWherein) . ') '; $this->aWhere[] = $whereIn; $this->aWherein = array(); return $this; } /** * Set LIKE clause * * @access public * @param type $field * @param type $match * @param type $side * @return DBCommandClass */ function like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'AND ', $side); } /** * Set NOT LIKE clause using AND operator * * @access public * @since 2.3 * @param string $field * @param string $match * @param string $side * @return DBCommandClass */ function notLike($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'AND ', $side, 'NOT'); } /** * Set LIKE clause using OR operator * * @access public * @since 2.3 * @param string $field * @param string $match * @param type $side * @return string */ function orLike($field, $match = '', $si