We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
emm 都不关闭数据库连接的吗
The text was updated successfully, but these errors were encountered:
看了一下 CloseDB 没有调用
Sorry, something went wrong.
@luodaozhang @iflamed 首先需要有个基础概念,如下:
sql.Open() 实际上不建立与数据库的任何连接。也不验证驱动程序连接参数。相反,它只是准备数据库抽象以供以后使用。当第一次需要时,将懒惰地建立与底层数据库实例的第一个实际连接
sql.Open()
在本项目中,我们将 sql.DB 视为一个长期使用的包全局对象,它是一个连接池。不需要频繁 Open() 和 Close(),需要的是为不同的数据库请求返回不同的连接句柄
sql.DB
Open()
Close()
而每次都 defer db.Close() 的行为更适合当该连接句柄已超出其生存函数时,应当关闭
defer db.Close()
那么显然,用法上就不一样了
使用的是长链接。只有程序终止的时候才调用close。
No branches or pull requests
emm 都不关闭数据库连接的吗
The text was updated successfully, but these errors were encountered: