Execute the query
@param        $sql
@param string $bind
@return array|bool|int
17563
public function run($sql, $bind = "")
    {
        $this->_sql = trim($sql);
        $this->_bind = $this->cleanup($bind);
        $this->_error = "";

        try {
            $start = microtime(true);
            $pdostmt = $this->prepare($this->_sql);
            if ($pdostmt->execute($this->_bind) !== false) {
                if (preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this->_sql))
                {
                    $return = ($this->limit == 1)? $pdostmt->fetch(\PDO::FETCH_ASSOC) : $pdostmt->fetchAll(\PDO::FETCH_ASSOC);
                }
                elseif (preg_match("/^(" . implode("|", array("delete", "update")) . ") /i", $this->_sql))
                {
                    $return = $pdostmt->rowCount();
                }
                elseif (preg_match("/^(" . implode("|", array("insert")) . ") /i", $this->_sql))
                {
                    $return = $this->lastInsertId();
                }
            }


            if ($this->print) {
                $time = microtime(true) - $start;
                $queryPreview = $this->interpolateQuery($this->_sql, $this->_bind);
                print_r($queryPreview);
            }

            return $return;

        } catch (PDOException $e) {
            $this->_error = $e->getMessage();
            if($this->print) {
                $queryPreview = $this->interpolateQuery($this->_sql, $this->_bind);
                print_r($queryPreview);
            }
            $this->debug();
            return false;
        }
    }
1196314
public function fetchOne($sql, $bind = array())
    {
        $stmt = $this->query($sql, $bind);
        $result = $stmt->fetchColumn(0);
        return $result;
    }
378883
private function logSql($sql, array $bind = []) {
        if (!Config::get('app', 'debug')) {
            return;
        }
        if ($bind) {
            foreach ($bind as $key => $val) {
                $value = is_array($val) ? $val[ 0 ] : $val;
                $type = is_array($val) ? $val[ 1 ] : PDO::PARAM_STR;
                if (PDO::PARAM_STR == $type) {
                    $value = $this->pdo->quote($value);
                } elseif (PDO::PARAM_INT == $type && '' === $value) {
                    $value = 0;
                }
                // 判断占位符
                $sql = is_numeric($key) ? substr_replace($sql, $value, strpos($sql, '?'), 1) : str_replace([':' . $key . ')',
                                                                                                            ':' . $key . ',',
                                                                                                            ':' . $key . ' '], [$value . ')',
                                                                                                                                $value . ',',
                                                                                                                                $value . ' '], $sql . ' ');
            }
        }
        $this->queryStr = rtrim($sql);
        Log::debug($this->queryStr, 'sql');
        return;
    }
1080740
public function bind($sql, array $params=array())
    {
        return $this->_bindInto('\?', $sql, $params, function($binder, $param) use ($sql) {
            return $binder->sqlValue($param);
        });
    }
737181
protected function _execute($sql)
	{
		return ibase_query(isset($this->_ibase_trans) ? $this->_ibase_trans : $this->conn_id, $sql);
	}
540734
public function query($sql, $bind = [], $master = false, $class = false)
    {
        return $this->connection->query($sql, $bind, $master, $class);
    }
1193708
protected function execute($sql, array $data = array())
    {
        try{
            foreach ($data as $key => $value) {
                $sql = str_replace(":".$key, "'".$value."'", $sql);
            }

            $execute = mssql_query($sql,$this->raw);

        }catch(\Exception $e){
            return null;
        }
        

        return $execute;
    }
944900
public function queryFast(string $sql, $bind = []): array
    {
        $connect = $this->connectWrite();

        // 先记日志,以免错误导致无日志
        FileLog::instance()->sqlBefore('queryFast', $sql);

        //快速查询不记录查询结果日志
        if (!$bind) {
            return $connect->query($sql, \PDO::FETCH_ASSOC)->fetchAll();
        }

        //带参数绑定
        return $this->bindQuery($connect, $sql, $bind);
    }
239648
public function statement($sql, $bindings = array())
		{
			list($statement, $result) = $this->execute($sql, $bindings);
			return $result;
		}
1194404
public function compile_binds($sql, $binds,$pattern)
    {
        return preg_replace_callback($pattern, function($m) use ($binds){
            if(isset($binds[$m[1]])){ // If it exists in our array
                return $binds[$m[1]]; // Then replace it from our array
            }

            return $m[0]; // Otherwise return the whole match (basically we won't change it)
        }, $sql);
    }
996562
public function query(string $sql, $data = null) {
		$connection = $this->pool->getConnection();
		$result = null;
		$tryAgain = true;
SQL_START_EXECUTE:
		if (is_array($data) && count($data) > 0) {
			if (strpos($sql, ':') !== false) {
				$bind = [];
				$sql = preg_replace_callback('/:(\w+)\b/', function ($matches) use (&$data, &$bind) {
					$bind[] = $data[$matches[1]];
					return '?';
				}, $sql);
				$data = &$bind;
			}
			try {
				$st = $connection->prepare($sql);
				if ($st === false) {
					goto SQL_TRY_AGAIN;
				}
				if (is_object($st)) {
					$result = $st->execute($data);
				} else {
					$result = $connection->execute($data);
				}
			} catch (\Throwable $e) {
				goto SQL_TRY_AGAIN;
			}
			if ($result === false) {
				goto SQL_TRY_AGAIN;
			}
			goto SQL_SUCCESS_RETURN;
		} else {
			try {
				$result = $connection->query($sql);
			} catch (\Throwable $e) {
				goto SQL_TRY_AGAIN;
			}
			if ($result === false) {
				goto SQL_TRY_AGAIN;
			}
			goto SQL_SUCCESS_RETURN;
		}
SQL_TRY_AGAIN:
		if (($connection->errno === 2006 || $connection->errno === 2013) && $tryAgain) {
			$tryAgain = false;
			$connection = $this->pool->reconnect($connection);
			goto SQL_START_EXECUTE;
		} else {
			$error = $connection->error;
			$errno = $connection->errno;
			$this->pool->freeConnection($connection);
			throw new DBException($error, $errno);
		}
SQL_SUCCESS_RETURN:
		if ($result === true) {
			$result = [
				'_affected_rows' => $connection->affected_rows
			];
			if (stripos($sql, 'insert') === 0) {
				$result['_insert_id'] = $connection->insert_id;
			}
		}
		$this->pool->freeConnection($connection);
		return $result;
	}
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;
    }
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;
    }
868850
public static function execute($sql, $bind = []) {
        /* @var $connection Connection */
        $connection = Pool::get(Connection::class);
        try {
            $connection->execute($sql, $bind);
            Pool::release($connection);
        } catch (\RuntimeException $e) {
            Pool::release($connection);
            throw $e;
        } catch (\Error $e) {
            Pool::release($connection);
            throw $e;
        }

    }
963217
public function query($sql)
    {
        $result = $this->pdo->query($sql);
        $this->executed[] = $sql;
        return $result;
    }
607851
public function execute($sql = null, $parameters = array()) {
        if (empty($sql)) {
            return null;
        }
        foreach ($parameters as $key => $item) {
            Str::bindParam($sql, $key + 1, $item, is_numeric($item) ? 'INT' : 'STR');
        }
        $this->result = mysql_query($sql, $this->driver);
        Factory::log()->info(sprintf('MYSQL: %s => %s', $sql,
            $this->getError()));
        return $this->result;
    }
140101
public function exec(string $sql, array $bind = []): FetchAbstract
    {
        if ($bind) {
            $stmt = $this->handle->prepare($sql);
            foreach ($bind as $name => $val) {
                $type = $this->getArgType($val);
                $stmt->bindValue(':' . $name, $val, $type);
            }

            $result = $stmt->execute();
        } else {
            $result = $this->handle->query($sql);
        }

        return new SqliteFetch($sql, $result);
    }