package main
import "fmt"
import "database/sql"
import _ "github.com/go-sql-driver/mysql"
type Vr struct {
name string
vrurl string
belong string
vrid int
}
func main() {
var Vr1 Vr
var Vr2 Vr
Vr1.name = "跪射俑"
Vr1.vrurl = "http:"
Vr1.belong = "一号坑"
Vr1.vrid = 1
Vr2.name = "铜车马俑"
Vr2.vrurl = "http:"
Vr2.belong = "展览厅"
Vr2.vrid = 2
db, err := sql.Open("mysql", "root:root@/ai?charset=utf8")
checkErr(err)
//查询数据
rows, err := db.Query("SELECT * FROM users")
checkErr(err)
for rows.Next() {
var uid int
var name string
var age string
var sex string
err = rows.Scan(&uid, &name, &age, &sex)
checkErr(err)
fmt.Println(name)
fmt.Println(age)
fmt.Println(sex)
}
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
有疑问加站长微信联系(非本文作者)