db, err := sql.Open("mysql", "fdfd:123456@tcp(127.0.0.1:3306)/test?charset=utf8")
if err != nil {
fmt.Println("database initialize error : ", err.Error())
}
stmt, err := db.Prepare("insert into test(cate_id, title, content)values(?, ?, ?)")
if err != nil {
fmt.Println(err.Error())
return
}
defer stmt.Close()
if result, err := stmt.Exec(cate_id, title, content); err == nil {
if id, err := result.LastInsertId(); err == nil {
fmt.Printf("thread: %d;\tinsert id : %d\n", i, id)
}
}
go mysql 添加数据_使用go脚本向MySQL表中写入数据
最新推荐文章于 2023-07-05 19:27:12 发布