src/Db/MySqlDb.php
protected function buildWhere($where, $op = Db::OP_AND, $quotevals = true) {
        static $map = array(Db::OP_GT => '>', Db::OP_GTE => '>=', Db::OP_LT => '<', Db::OP_LTE => '<=', Db::OP_LIKE => 'like');

        $result = '';
        foreach ($where as $column => $value) {
            $btcolumn = $this->backtick($column);

            if (is_array($value)) {
                if (isset($value[0])) {
                    // This is a short in syntax.
                    $value = [Db::OP_IN => $value];
                }

                foreach ($value as $vop => $rval) {
                    if ($result) {
                        $result .= "\n  $op ";
                    }

                    switch ($vop) {
                        case Db::OP_AND:
                        case Db::OP_OR:
                            $innerWhere = [$column => $rval];
                            $result .= "(\n  ".
                                $this->buildWhere($innerWhere, $vop, $quotevals).
                                "\n  )";
                            break;
                        case Db::OP_EQ:
                            if ($rval === null) {
                                $result .= "$btcolumn is null";
                            } elseif (is_array($rval)) {
                                $result .= "$btcolumn in ".$this->bracketList($rval);
                            } else {
                                $result .= "$btcolumn = ".$this->quoteVal($rval, $quotevals);
                            }
                            break;
                        case Db::OP_GT:
                        case Db::OP_GTE:
                        case Db::OP_LT:
                        case Db::OP_LTE:
                            $result .= "$btcolumn {$map[$vop]} ".$this->quoteVal($rval, $quotevals);
                            break;
                        case Db::OP_LIKE:
                            $result .= $this->buildLike($btcolumn, $rval, $quotevals);
                            break;
                        case Db::OP_IN:
                            // Quote the in values.
                            $rval = array_map(array($this->pdo, 'quote'), (array)$rval);
                            $result .= "$btcolumn in (".implode(', ', $rval).')';
                            break;
                        case Db::OP_NE:
                            if ($rval === null) {
                                $result .= "$btcolumn is not null";
                            } elseif (is_array($rval)) {
                                $result .= "$btcolumn not in ".$this->bracketList($rval);
                            } else {
                                $result .= "$btcolumn <> ".$this->quoteVal($rval, $quotevals);
                            }
                            break;
                    }
                }
            } else {
                if ($result) {
                    $result .= "\n  $op ";
                }

                // This is just an equality operator.
                if ($value === null) {
                    $result .= "$btcolumn is null";
                } else {
                    $result .= "$btcolumn = ".$this->quoteVal($value, $quotevals);
                }
            }
        }
        return $result;
    }
protected function buildWhere($where, $op = Db::OP_AND, $quotevals = true) {
        static $map = array(Db::OP_GT => '>', Db::OP_GTE => '>=', Db::OP_LT => '<', Db::OP_LTE => '<=', Db::OP_LIKE => 'like');

        $result = '';
        foreach ($where as $column => $value) {
            $btcolumn = $this->backtick($column);

            if (is_array($value)) {
                if (isset($value[0])) {
                    // This is a short in syntax.
                    $value = [Db::OP_IN => $value];
                }

                foreach ($value as $vop => $rval) {
                    if ($result) {
                        $result .= "\n  $op ";
                    }

                    switch ($vop) {
                        case Db::OP_AND:
                        case Db::OP_OR:
                            $innerWhere = [$column => $rval];
                            $result .= "(\n  ".
                                $this->buildWhere($innerWhere, $vop, $quotevals).
                                "\n  )";
                            break;
                        case Db::OP_EQ:
                            if ($rval === null) {
                                $result .= "$btcolumn is null";
                            } elseif (is_array($rval)) {
                                $result .= "$btcolumn in ".$this->bracketList($rval);
                            } else {
                                $result .= "$btcolumn = ".$this->quoteVal($rval, $quotevals);
                            }
                            break;
                        case Db::OP_GT:
                        case Db::OP_GTE:
                        case Db::OP_LT:
                        case Db::OP_LTE:
                            $result .= "$btcolumn {$map[$vop]} ".$this->quoteVal($rval, $quotevals);
                            break;
                        case Db::OP_LIKE:
                            $result .= $this->buildLike($btcolumn, $rval, $quotevals);
                            break;
                        case Db::OP_IN:
                            // Quote the in values.
                            $rval = array_map(array($this->pdo, 'quote'), (array)$rval);
                            $result .= "$btcolumn in (".implode(', ', $rval).')';
                            break;
                        case Db::OP_NE:
                            if ($rval === null) {
                                $result .= "$btcolumn is not null";
                            } elseif (is_array($rval)) {
                                $result .= "$btcolumn not in ".$this->bracketList($rval);
                            } else {
                                $result .= "$btcolumn <> ".$this->quoteVal($rval, $quotevals);
                            }
                            break;
                    }
                }
            } else {
                if ($result) {
                    $result .= "\n  $op ";
                }

                // This is just an equality operator.
                if ($value === null) {
                    $result .= "$btcolumn is null";
                } else {
                    $result .= "$btcolumn = ".$this->quoteVal($value, $quotevals);
                }
            }
        }
        return $result;
    }
Build a where clause from a where array.

@param array $where There where string.
This is an array in the form `['column' => 'value']` with more advanced options for non-equality comparisons.
@param string $op The logical operator to join multiple field comparisons.
@param bool $quotevals Whether or not to quote the where values.
@return string The where string.