package main
import (
"database/sql"
. "fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "root:root@/zuo?charset=utf8")
if err == nil {
Println("hahahah")
}
stmt, err := db.Prepare(`INSERT pet (name,owner) values (?,?)`)
if err == nil {
Println("haha")
}
res, err := stmt.Exec("zuo", "Mary")
if err == nil {
Println("hahha2")
}
// checkErr(err)
id, err := res.LastInsertId()
if err == nil {
Println("hahah3")
}
// checkErr(err)
Println(id)
}
import (
"database/sql"
. "fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "root:root@/zuo?charset=utf8")
if err == nil {
Println("hahahah")
}
stmt, err := db.Prepare(`INSERT pet (name,owner) values (?,?)`)
if err == nil {
Println("haha")
}
res, err := stmt.Exec("zuo", "Mary")
if err == nil {
Println("hahha2")
}
// checkErr(err)
id, err := res.LastInsertId()
if err == nil {
Println("hahah3")
}
// checkErr(err)
Println(id)
}
有疑问加站长微信联系(非本文作者)