[215] Gin Framework connection to MySQL Database

Milokou 2022-07-23 18:05:25 阅读数:650

ginframeworkconnectionmysqldatabase
package main
import (
"fmt"
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func main(){

db,err:=sql.Open("mysql","root:[email protected](127.0.0.1:3306)/djangoblog")
if err != nil{

panic(err)
}
defer db.Close()
if err:=db.Ping();err!=nil{

fmt.Println("La connexion a échoué")
panic(err)
}
fmt.Println("Connexion réussie")
}
Copyright:Cet article est[Milokou]Établi,Veuillez apporter le lien original pour réimprimer,remercier。 https://fra.fheadline.com/2022/204/202207231536097803.html