参数绑定
支持 ['name'=>'value','id'=>123] 对应命名占位符
或者 ['value',123] 对应问号占位符

@param array $bind

@throws \Exception
353511
protected function bindValue(array $bind = []) {
        foreach ($bind as $key => $val) {
            // 占位符
            $param = is_numeric($key) ? $key + 1 : ':' . $key;
            if (is_array($val)) {
                if (PDO::PARAM_INT == $val[ 1 ] && '' === $val[ 0 ]) {
                    $val[ 0 ] = 0;
                }
                $this->PDOStatement->bindValue($param, $val[ 0 ], $val[ 1 ]);
            } else {
                $this->PDOStatement->bindValue($param, $val);
            }
        }
    }
1058694
public function addSelect($fields, $bind = [])
    {
        if (!is_array($fields)) {
            $fields = [$fields];
        }

        foreach ($fields as $key => $field) {
            if ($field instanceof Entity) {
                $query = $field->getQuery();
                $this->bind($query->buildBinds(), 'select');
                if (is_numeric($key)) {
                    $this->select[] = '(' . $query->buildSQL() . ')';
                } else {
                    $this->select[$key] = '(' . $query->buildSQL() . ')';
                }
            } elseif ($field instanceof Raw) {
                $this->bind($field->buildBinds(), 'select');
                if (is_numeric($key)) {
                    $this->select[] = $field->buildSQL();
                } else {
                    $this->select[$key] = $field->buildSQL();
                }
            } elseif (is_numeric($key)) {
                $this->select[] = $field;
            } else {
                $this->select[$key] = $field;
            }
        }

        if ($bind) {
            $this->bind($bind, 'select');
        }

        return $this;
    }
1150230
public function fetchPairs($sql, $bind = array())
    {
        $stmt = $this->query($sql, $bind);
        $data = array();
        while ($row = $stmt->fetch(Zend_Db::FETCH_NUM)) {
            $data[$row[0]] = $row[1];
        }
        return $data;
    }
638351
public function value($sql, $bind = [], $cache = false) {
        $value = null;
        $dbCache = null;
        if ($cache) {
            /* @var $dbCache DBCache */
            $dbCache = Ioc::get(DBCache::class);
            $value = $dbCache->queryCache($sql, $bind);
            if($value){
                return $value['value'];
            }
        }
        if ($value == null) {
            $this->execute($sql, $bind);
            $value = $this->PDOStatement->fetchColumn();
            if ($cache) {
                $dbCache->saveCache($sql, $bind, ['value'=>$value]);
            }
        }
        return $value;
    }
4830
public function prepareSQL($sql, $binds = [])
    {
        $prepare = $this->getConnection()->prepare($sql);

        if (!$prepare) {
            throw new Exception('Cannot prepare statement');
        }

        $this->bindBinds($prepare, $binds);

        $prepare->setFetchMode(\PDO::FETCH_OBJ);

        return $prepare;
    }
272198
public final function fetchRow($sql, array $bind = [])
    {
        return $this->query($sql, $bind)->fetch(\PDO::FETCH_NAMED);
    }
1207920
protected function parseDataBind(Query $query, $key, $data, $bind = [])
    {
        if ($data instanceof Expression) {
            return $data->getValue();
        }

        $name = $query->bind($data, isset($bind[$key]) ? $bind[$key] : PDO::PARAM_STR);

        return ':' . $name;
    }
938038
protected function bindAttr($model, &$result)
    {
        foreach ($this->bindAttr as $key => $attr) {
            $key = is_numeric($key) ? $attr : $key;
            if (isset($result->$key)) {
                throw new Exception('bind attr has exists:' . $key);
            } else {
                $result->setAttr($key, $model ? $model->$attr : null);
            }
        }
    }
628262
protected function initializeBinding(Binding $binding)
    {
        $binding->initialize($this->getBindingType($binding->getTypeName()));

        $bindingClass = get_class($binding);

        if (!isset($this->initializersByBindingClass[$bindingClass])) {
            $this->initializersByBindingClass[$bindingClass] = array();

            // Find out which initializers accept the binding
            foreach ($this->initializers as $initializer) {
                if ($initializer->acceptsBinding($bindingClass)) {
                    $this->initializersByBindingClass[$bindingClass][] = $initializer;
                }
            }
        }

        // Apply all initializers that we found
        foreach ($this->initializersByBindingClass[$bindingClass] as $initializer) {
            $initializer->initializeBinding($binding);
        }
    }
999718
public function execute($sql, $bind = [])
    {
        $this->initConnect(true);
        if (!$this->linkID) {
            return false;
        }

        // 记录SQL语句
        $this->queryStr = $sql;
        if ($bind) {
            $this->bind = $bind;
        }

        //释放前次的查询结果
        if (!empty($this->PDOStatement) && $this->PDOStatement->queryString != $sql) {
            $this->free();
        }

        Db::$executeTimes++;
        try {
            // 预处理
            if (empty($this->PDOStatement)) {
                $this->PDOStatement = $this->linkID->prepare($sql);
            }
            // 是否为存储过程调用
            $procedure = in_array(strtolower(substr(trim($sql), 0, 4)), ['call', 'exec']);
            // 参数绑定
            if ($procedure) {
                $this->bindParam($bind);
            } else {
                $this->bindValue($bind);
            }
            // 执行语句
            $this->PDOStatement->execute();

            $this->numRows = $this->PDOStatement->rowCount();
            return $this->numRows;
        } catch (\PDOException $e) {
            if ($this->isBreak($e)) {
                return $this->close()->execute($sql, $bind);
            }
            throw new PDOException($e, $this->config, $this->getLastsql());
        } catch (\ErrorException $e) {
            if ($this->isBreak($e)) {
                return $this->close()->execute($sql, $bind);
            }
            throw $e;
        }
    }
727849
public function insert($table, array $bind)
    {
        // extract and quote col names from the array keys
        $cols = array();
        $vals = array();
        $i = 0;
        foreach ($bind as $col => $val) {
            $cols[] = $this->quoteIdentifier($col, true);
            if ($val instanceof Zend_Db_Expr) {
                $vals[] = $val->__toString();
                unset($bind[$col]);
            } else {
                if ($this->supportsParameters('positional')) {
                    $vals[] = '?';
                } else {
                    if ($this->supportsParameters('named')) {
                        unset($bind[$col]);
                        $bind[':col'.$i] = $val;
                        $vals[] = ':col'.$i;
                        $i++;
                    } else {
                        /** @see Zend_Db_Adapter_Exception */
                        // require_once 'Zend/Db/Adapter/Exception.php';
                        throw new Zend_Db_Adapter_Exception(get_class($this) ." doesn't support positional or named binding");
                    }
                }
            }
        }

        // build the statement
        $sql = "INSERT INTO "
             . $this->quoteIdentifier($table, true)
             . ' (' . implode(', ', $cols) . ') '
             . 'VALUES (' . implode(', ', $vals) . ')';

        // execute the statement and return the number of affected rows
        if ($this->supportsParameters('positional')) {
            $bind = array_values($bind);
        }
        $stmt = $this->query($sql, $bind);
        $result = $stmt->rowCount();
        return $result;
    }
955720
protected function bindMethods(array $binds)
    {
        $self = $this;
        foreach ($binds as $eventName => $methodName) {
            $this->client->on(
                $eventName,
                function () use ($self, $methodName, $eventName) {
                    $self->{$methodName}(func_get_args(), $eventName);
                }
            );
        }
    }
918642
public function insert($table, array $bind)
    {
        // extract and quote col names from the array keys
        $cols = array();
        $vals = array();
        foreach ($bind as $col => $val) {
            $cols[] = $this->quoteIdentifier($col, true);
            if ($val instanceof Zend_Db_Expr) {
                $vals[] = $val->__toString();
                unset($bind[$col]);
            } else {
                $vals[] = '?';
            }
        }

        // build the statement
        $sql = "INSERT INTO "
             . $this->quoteIdentifier($table, true)
             . ' (' . implode(', ', $cols) . ') '
             . 'VALUES (' . implode(', ', $vals) . ')'
             . ' ' . $this->_lastInsertSQL;

        // execute the statement and return the number of affected rows
        $stmt   = $this->query($sql, array_values($bind));
        $result = $stmt->rowCount();

        $stmt->nextRowset();

        $this->_lastInsertId = $stmt->fetchColumn();

        return $result;
    }
1210011
public function bindValues($values): void
    {
        $params = func_get_args();
        if (isset($params[0]) && is_array($params[0])) {
            $this->bindedValues = new \ArrayObject($params[0]);
        } else {
            $this->bindedValues = new \ArrayObject($params);
        }
    }
1264500
public function setValues($values)
    {
        if (!$this->rows) {
            throw new \Exception('You must setRows() before setValues');
        }
        $this->values = $values;

        $valueCount = count($values);
        $fieldCount = count($this->rows);

        // Build the Placeholder String
        $placeholders = [];
        for ($i = 0; $i < $valueCount; $i++) {
            $placeholders[] = '(' . rtrim(str_repeat('?,', $fieldCount), ',') . ')';
        }
        $this->bindString = implode(',', $placeholders);

        // Build the Flat Value Array
        $valueList = [];
        foreach ($values as $value) {
            if (is_array($value)) {
                foreach ($value as $v) {
                    $valueList[] = $v;
                }
            } else {
                $valueList[] = $values;
            }
        }
        $this->valuesFlattened = $valueList;
        unset($valueList);

        return $this;
    }
261565
@Deprecated
	public void bind(String name, Object value)
	{
		if (name2Index == null)
		{
			throw new RuntimeException("申明的绑定和代码里实际绑定不一致");
		}
		Integer index = name2Index.get(name);
		if (index == null)
		{
			throw new RuntimeException("申明的绑定和代码里实际绑定不一致:试图绑定未申明的变量" + name);
		}
		ctx.vars[index] = value;
	}
1243862
private function bindValues(array $values)
    {
        $this->bindedParameters = array();
        $this->bindedTypes = array();
        $this->bindedValues = array();

        foreach ($values as $parameter => $value) {
            if (is_int($parameter)) {
                $parameter++;
            }

            $this->bindValue($parameter, $value);
        }
    }