You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
966 B

1 year ago
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"time"
)
type Account struct {
Id int64 `db:"id"`
UserId int64 `db:"user_id"`
UserType int64 `db:"user_type"` // 1 user 2 employer
Name string `db:"name"`
Email string `db:"email"`
Password string `db:"password"`
Phone string `db:"phone"` // +80-18010489927
WechatUniqueId string `db:"wechat_unique_id"`
}
func main() {
dsn := "root:123456@tcp(127.0.0.1:3306)/test_gozero"
db, err := sql.Open("mysql", dsn)
if err != nil {
panic(err)
}
db.SetConnMaxLifetime(time.Minute * 3)
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)
if err = db.Ping(); err != nil {
panic(err)
}
smt, err := db.Prepare("insert into account (user_id)values (?)")
if err != nil {
panic(err)
}
res, err := smt.Exec(1, 3)
if err != nil {
panic(err)
}
fmt.Println(res.LastInsertId())
fmt.Println(res.RowsAffected())
}