【发布时间】:2015-09-19 12:32:51
【问题描述】:
我正在尝试使用 go 语言获取 mysql 数据库中的多个列。目前我可以修改这个脚本,它可以很好地获取一列,并使用 http 打印功能打印它。但是,当它获取两件事时,脚本不再起作用。我不知道我需要做什么来修复它。我知道 sql 很好,因为我已经在 mysql 终端中对其进行了测试,它给了我想要的预期结果。
conn, err := sql.Open("mysql", "user:password@tcp(localhost:3306)/database")
statement, err := conn.Prepare("select first,second from table")
rows, err := statement.Query()
for rows.Next() {
var first string
rows.Scan(&first)
var second string
rows.Scan(&second)
fmt.Fprintf(w, "Title of first is :"+first+"The second is"+second)
}
conn.Close()
【问题讨论】:
-
什么是“http打印功能”?