其他的增删改都正常,就是查询代码出错
~~~
func select1(w http.ResponseWriter, r *http.Request) {
db, err := sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/test?charset=utf8")
checkErr(err)
//rows,err :=db.Query("select uid ,age form user_list where user ='guest'")
rows, err := db.Query("select * from user_list")
checkErr(err)
for rows.Next() {
var uid int
var user string
//var age int
rows.Columns()
err = rows.Scan(&uid, &user)
checkErr(err)
fmt.Fprintln(w, uid)
fmt.Fprintln(w, user)
//fmt.Fprintln(w, age)
}
//关闭数据库
db.Close()
}
~~~
有疑问加站长微信联系(非本文作者)