快速版查询,不记录日志,返回句柄
@param $sql string 要查询的语句
@param array|string $bind 要绑定的参数
@return \PDOStatement
180057
public function queryFastHandle(string $sql, $bind = []): \PDOStatement
    {
        if (!$bind) {
            return $this->connectWrite()->query($sql, \PDO::FETCH_ASSOC);
        }

        $stmt = $this->connectWrite()->prepare($sql);
        $ret = $stmt->execute($bind);

        //通常是参数绑定问题
        if (!$ret) {
            trigger_error('PDO语句参数绑定错误:' . $stmt->errorCode(), E_USER_ERROR);
        }
        return $stmt;
    }
1158740
protected function executeUpdate($sql,$bindparams=NULL) {
		$result = $this->db->handle->prepare($sql);
		$result->execute($bindparams);
		if ($result->errorCode() == '00000') {
			return true;
		} 
		$this->logStatementError($result->errorInfo(),$sql);
		return false;
	}
652192
protected function replaceBindings($sql, array $bindings)
    {
        $generalRegex = $this->getRegex();

        foreach ($this->formatBindings($bindings) as $key => $binding) {
            $regex = is_numeric($key) ? $generalRegex : $this->getNamedParameterRegex($key);
            $sql = preg_replace($regex, $this->value($binding), $sql, 1);
        }

        return $sql;
    }
784723
function insert($table, array $bind)
    {
        $sql = $this->insertSql($table, $bind);
        // execute the statement and return the number of affected rows
        $stmt = $this->wrappedAdapter->query($sql, array_values($bind));
        $result = $stmt->rowCount();
        return $result;
    }
1168612
public function fetchOne($sql, $bind = [], $fetchMode = \PDO::FETCH_ASSOC, $useMaster = false)
    {
        return ($rs = $this->fetchAll($sql, $bind, $fetchMode, $useMaster)) ? $rs[0] : false;
    }
480853
public function fetchCol($sql, $bind = array())
    {
        $stmt = $this->query($sql, $bind);
        $result = $stmt->fetchAll(Zend_Db::FETCH_COLUMN, 0);
        return $result;
    }
565111
public static function raw($sql, $binds = [], $part = 'main')
    {
        $query = new static($sql);

        if (!is_array($binds)) {
            $binds = [$binds];
        }

        foreach ($binds as $bind) {
            $query->bind($bind, $part);
        }

        return $query;
    }
1196314
public function fetchOne($sql, $bind = array())
    {
        $stmt = $this->query($sql, $bind);
        $result = $stmt->fetchColumn(0);
        return $result;
    }
501740
public static function updateBySql($sql)
    {
        if (is_array($sql)) {
            $bind = $sql;
            unset($bind[0]);
            $sql = $sql[0];
        } else {
            $bind = [];
        }

        $model = new static;

        $table = $model->getSource($bind);
        return $model->getConnection($bind)->updateBySql('UPDATE' . " [$table] SET " . $sql, $bind);
    }
222201
public function query($sql)
    {
        $this->numExecutes++;
        $this->numStatements++;
        
        $pdos = $this->_pdo->query($sql);
        
        return new PDOStatement($this, $pdos);
    }
1080330
public function queryCache($sql, $bind = []) {
        $redis = Cache::redis();
        if (!$redis) {
            //没有使用 redis 不支持二级缓存
            return null;
        }
        $key = $this->cacheKey($sql, $bind);
        $cache_name = $this->cacheName($sql);
        $result = Cache::hashGet($cache_name, $key);
        if ($result) {
            Log::debug("命中缓存" . $sql . json_encode($bind), 'cache');
        }
        return $result;
    }
1082652
private function binding(\PDOStatement $sql, array $bindings = []): \PDOStatement
    {
        foreach ($bindings as $binding=>$value) {
            if (!is_array($value)) {
                $sql->bindValue($binding, $value);
            } else {
                switch(strtolower($value[1])) {
                    case 'date':
                        $sql->bindValue($binding, $this->time($value[0], 'Y-m-d'), \PDO::PARAM_STR);
                        break;
                    case 'time':
                        $sql->bindValue($binding, $this->time($value[0], 'Y-m-d H:i:s.u'), \PDO::PARAM_STR);
                        break;
                    case 'bool':
                    case 'boolean':
                        $sql->bindValue($binding, boolval($value[0]), \PDO::PARAM_BOOL);
                        break;
                    case 'null':
                        $sql->bindValue($binding, NULL, \PDO::PARAM_NULL);
                        break;
                    case 'int':
                    case 'integer':
                    case 'number':
                    case 'limit':
                    case 'offset':
                        $sql->bindValue($binding, intval($value[0]), \PDO::PARAM_INT);
                        break;
                    case 'str':
                    case 'string':
                    case 'text':
                    case 'float':
                    case 'varchar':
                    case 'varchar2':
                        $sql->bindValue($binding, strval($value[0]), \PDO::PARAM_STR);
                        break;
                    case 'lob':
                    case 'large':
                    case 'object':
                    case 'blob':
                        $sql->bindParam($binding, $value[0], \PDO::PARAM_LOB, strlen($value[0]));
                        break;
                    case 'like':
                        $sql->bindValue($binding, '%'.$value[0].'%', \PDO::PARAM_STR);
                        break;
                    default:
                        if (is_int($value[1])) {
                            $sql->bindValue($binding, $value[0], $value[1]);
                        } else {
                            $sql->bindValue($binding, strval($value[0]), \PDO::PARAM_STR);
                        }
                }
            }
        }
        return $sql;
    }
1366580
public function prepare($sql)
    {
        $connection = ConnectionManager::getConnection();
        $statement = $connection->prepare($sql);
        $statement->setFetchMode(\PDO::FETCH_NUM);
        return $statement;
    }
422532
public static function insertBySql($sql)
    {
        if (is_array($sql)) {
            $bind = $sql;
            unset($bind[0]);
            $sql = $sql[0];
        } else {
            $bind = [];
        }

        $model = new static;

        $table = $model->getSource($bind);
        return $model->getConnection($bind)->insertBySql('INSERT' . " INTO [$table] " . $sql, $bind);
    }
875159
protected function _execute($type, $sql, $bind = [])
    {
        $context = $this->_context;

        $context->sql = $sql;
        $context->bind = $bind;

        $context->affected_rows = 0;

        $this->eventsManager->fireEvent('db:before' . ucfirst($type), $this);

        if ($context->connection) {
            $connection = $context->connection;
        } else {
            $connection = $this->poolManager->pop($this, $this->_timeout);
        }

        try {
            $start_time = microtime(true);
            $context->affected_rows = $connection->execute($sql, $bind);
            $elapsed = round(microtime(true) - $start_time, 3);
        } finally {
            if (!$context->connection) {
                $this->poolManager->push($this, $connection);
            }
        }

        $count = $context->affected_rows;
        $event_data = compact('count', 'sql', 'bind', 'elapsed');
        if (is_int($context->affected_rows)) {
            $this->eventsManager->fireEvent('db:after' . ucfirst($type), $this, $event_data);
        }

        $this->logger->info($event_data, 'db.' . $type);
        return $count;
    }
540734
public function query($sql, $bind = [], $master = false, $class = false)
    {
        return $this->connection->query($sql, $bind, $master, $class);
    }
516700
public function update($table, $set, $where, $bind = array())
    {
        $sql = "UPDATE " . $table . " SET ";

        if(is_array($set)) {
            foreach($set as $field => $value) {
                $sql .= $field ." = ". $value . ",";
            }

            $sql = rtrim($sql,",");

        }else{
            $sql .= $set;
        }


        $sql .= " WHERE " . $where . ";";

        $bind = $this->cleanup($bind);

        return $this->run($sql, $bind);
    }