如何在Go中使用SQL Server包?

huangapple go评论91阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2015年8月9日 13:33:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/31901235.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定