I use xorm to connect to my mysql database,but when my mysql doesn't start,xorm cann't print error message
package main
import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"xorm.io/xorm"
)
var engine *xorm.Engine
func main() {
var err error
engine, err = xorm.NewEngine("mysql", "root:1234567@/blog?charset=utf8mb4")
if err != nil {
fmt.Println(err.Error())//can't print
return
}
}
CodePudding user response:
Use the Ping
method to check whether the database is alive
if err := engine.Ping(); err != nil {
panic(err)
}