1234567891011121314151617 |
- package util
- import (
- "database/sql"
- "fmt"
- "sync-block/er"
- _ "github.com/go-sql-driver/mysql"
- )
- func ConnectDb(host, id, pw, dbName string) *sql.DB {
- db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?parseTime=true",
- id, pw, host, dbName))
- er.Check(err)
- er.Check(db.Ping())
- return db
- }
|