public function action($action, $table, $where = array(), $options = array())
    {
        $sql   = "{$action} FROM {$table}";
        $value = array();

        if (!empty($where)) {

            $sql .= " WHERE ";

            foreach ($where as $clause) {
                if (count($clause) === 3) {

                    $operators = array('=', '>', '<', ' >=', '<=', '<>');

                    if (isset($clause)) {
                        $field     = $clause[0];
                        $operator  = $clause[1];
                        $value[]   = $clause[2];
                        $bindValue = '?';
                    }

                    if (in_array($operator, $operators)) {
                        $sql .= "{$field} {$operator} {$bindValue}";
                        $sql .= " AND ";
                    }
                }
            }
            $sql = rtrim($sql, " AND ");
        }

        if (!empty($options)) {
            foreach ($options as $optionKey => $optionValue) {
                $sql .= " {$optionKey} {$optionValue}";
            }
        }

        if (!$this->query($sql, $value)->error()) {
            return (object) $this;
        }

        return false;
    }
public function action($action, $table, $where = array(), $options = array())
    {
        $sql   = "{$action} FROM {$table}";
        $value = array();

        if (!empty($where)) {

            $sql .= " WHERE ";

            foreach ($where as $clause) {
                if (count($clause) === 3) {

                    $operators = array('=', '>', '<', ' >=', '<=', '<>');

                    if (isset($clause)) {
                        $field     = $clause[0];
                        $operator  = $clause[1];
                        $value[]   = $clause[2];
                        $bindValue = '?';
                    }

                    if (in_array($operator, $operators)) {
                        $sql .= "{$field} {$operator} {$bindValue}";
                        $sql .= " AND ";
                    }
                }
            }
            $sql = rtrim($sql, " AND ");
        }

        if (!empty($options)) {
            foreach ($options as $optionKey => $optionValue) {
                $sql .= " {$optionKey} {$optionValue}";
            }
        }

        if (!$this->query($sql, $value)->error()) {
            return (object) $this;
        }

        return false;
    }
public function action ( $ action , $ table , $ where = array ( ) , $ options = array ( ) ) { $ sql = "{$action} FROM {$table}" ; $ value = array ( ) ; if ( ! empty ( $ where ) ) { $ sql .= " WHERE " ; foreach ( $ where as $ clause ) { if ( count ( $ clause ) === 3 ) { $ operators = array ( '=' , '>' , '<' , ' >=' , '<=' , '<>' ) ; if ( isset ( $ clause ) ) { $ field = $ clause [ 0 ] ; $ operator = $ clause [ 1 ] ; $ value [ ] = $ clause [ 2 ] ; $ bindValue = '?' ; } if ( in_array ( $ operator , $ operators ) ) { $ sql .= "{$field} {$operator} {$bindValue}" ; $ sql .= " AND " ; } } } $ sql = rtrim ( $ sql , " AND " ) ; } if ( ! empty ( $ options ) ) { foreach ( $ options as $ optionKey => $ optionValue ) { $ sql .= " {$optionKey} {$optionValue}" ; } } if ( ! $ this -> query ( $ sql , $ value ) -> error ( ) ) { return ( object ) $ this ; } return false ; }
Method for dynamically generating SQL queries

@param string $action SQL statement
@param string $table Database table
@param array $where Multi-dimensional array for multiple WHERE statements
@param array $options Array with miscellaneous satements like ORDER BY
@return boolean|object
Method for dynamically generating SQL queries