package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
var db *sql.DB
func main() {
var err error
db, err = sql.Open("mysql", "root:xingfushenghuo999@tcp(127.0.0.1:3306)/college_journal?&collation=utf8mb4_unicode_ci&charset=utf8mb4&timeout=5s&readTimeout=15s&writeTimeout=15s")
if err != nil {
panic(err)
}
fmt.Println(db.Ping())
db_user_p, _ := db.Prepare("INSERT INTO user VALUES(?,?,?,?,?,?,now(),?,?,?)")
s, err := db_user_p.Exec(0, "18208142443", "大托普", "恒少", "男", "没有", "xingfusehnghuoasdjfijsa", "normal", "2")
if err != nil {
panic(err)
}
fmt.Println(s)
}
func CloseDb(){
defer db.Close()
}
panic: Error 1366: Incorrect string value: '\xE5\xA4\xA7\xE6\x89\x98...' for column 'school' at row 1
The error message is clear enough to help you check the problem.Make sure the value you insert match the type of that column
In case someone is looking for a solution.
https://github.com/jinzhu/gorm/issues/1811#issuecomment-421232477