MysqliDb::setQueryOption PHP Method

setQueryOption() public method

This method allows you to specify multiple (method chaining optional) options for SQL queries.
public setQueryOption ( string | array $options ) : MysqliDb
$options string | array The optons name of the query.
return MysqliDb
    public function setQueryOption($options)
    {
        $allowedOptions = array('ALL', 'DISTINCT', 'DISTINCTROW', 'HIGH_PRIORITY', 'STRAIGHT_JOIN', 'SQL_SMALL_RESULT', 'SQL_BIG_RESULT', 'SQL_BUFFER_RESULT', 'SQL_CACHE', 'SQL_NO_CACHE', 'SQL_CALC_FOUND_ROWS', 'LOW_PRIORITY', 'IGNORE', 'QUICK', 'MYSQLI_NESTJOIN', 'FOR UPDATE', 'LOCK IN SHARE MODE');
        if (!is_array($options)) {
            $options = array($options);
        }
        foreach ($options as $option) {
            $option = strtoupper($option);
            if (!in_array($option, $allowedOptions)) {
                throw new Exception('Wrong query option: ' . $option);
            }
            if ($option == 'MYSQLI_NESTJOIN') {
                $this->_nestJoin = true;
            } elseif ($option == 'FOR UPDATE') {
                $this->_forUpdate = true;
            } elseif ($option == 'LOCK IN SHARE MODE') {
                $this->_lockInShareMode = true;
            } else {
                $this->_queryOptions[] = $option;
            }
        }
        return $this;
    }

Usage Example

コード例 #1
0
 private function processHasOneWith()
 {
     if (count($this->_with) == 0) {
         return;
     }
     foreach ($this->_with as $name => $opts) {
         $relationType = strtolower($opts[0]);
         $modelName = $opts[1];
         $key = null;
         if (isset($opts[2])) {
             $key = $opts[2];
         }
         if ($relationType == 'hasone') {
             $this->db->setQueryOption("MYSQLI_NESTJOIN");
             $this->join($modelName, $key);
         }
     }
 }