英文:
how to use sql server packages in go
问题
我使用denisenkom/go-mssqldb包来连接SQL Server,但我不知道如何编写连接代码。这个方法sql.Open()
的参数是什么?例如,当我们写下这样的代码时:
db, err := sql.Open("mysql", "user:password@/database")
其中的"mysql"
和"user:password@/database"
代表什么?
在程序的哪个部分我们应该告诉程序我们要使用的数据库的名称?也就是说,在代码的哪个部分我们介绍要使用的数据库的名称?
英文:
I use the denisenkom/go-mssqldb package for connecting to SQL server in go but I don't know how to write the connecting code,
what are the arguments of this method : sql.Open()
for example when we say :
db, err := sql.Open("mysql", "user:password@/database")
what do "mysql"
and "user:password@/database"
refer to?
and in which part of the program we should tell the name of the database which we want to use in the program? I mean in which part of the code we introduce the name of the database we want to use?
答案1
得分: 1
"mssql"是您正在连接的协议/驱动程序/数据库类型。"user:password@/database"
是连接字符串。请参考此示例了解此字符串的组成部分。
您的应用程序通常知道要连接的数据库。或者至少在用户登录时知道。
英文:
"mssql" is the protocol/driver/database type you are connecting to. "user:password@/database"
is the connection string. See this example for the components of this String.
Your application typically knows the database it wants to connect. Or at last when the user logs in.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论