rogueserver/db/db.go

22 lines
386 B
Go
Raw Normal View History

2023-12-05 10:28:08 -08:00
package db
import (
"database/sql"
"fmt"
2023-12-28 16:58:54 -08:00
_ "github.com/go-sql-driver/mysql"
2023-12-05 10:28:08 -08:00
)
var handle *sql.DB
func Init(username, password, protocol, address, database string) error {
db, err := sql.Open("mysql", username+":"+password+"@"+protocol+"("+address+")/"+database)
if err != nil {
return fmt.Errorf("failed to open database connection: %s", err)
}
handle = db
return nil
}