Skip to content

Commit

Permalink
Mysql fix
Browse files Browse the repository at this point in the history
Fix the database driver connection, currently it only connects to localhost and port 3306 for mysql.
This fix it.
  • Loading branch information
joseluis2g committed Mar 21, 2019
1 parent d660162 commit 23e665d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 6 additions & 1 deletion app/app.go
Expand Up @@ -487,7 +487,12 @@ func connectDatabase() {
var err error

// Connect to the MySQL database
if database.DB, err = database.Open(lua.Config.GetGlobal("mysqlUser").String(), lua.Config.GetGlobal("mysqlPass").String(), lua.Config.GetGlobal("mysqlDatabase").String(), ""); err != nil {
if database.DB, err = database.Open(lua.Config.GetGlobal("mysqlUser").String(),
lua.Config.GetGlobal("mysqlPass").String(),
lua.Config.GetGlobal("mysqlHost").String(),
lua.Config.GetGlobal("mysqlPort").String(),
lua.Config.GetGlobal("mysqlDatabase").String(),
""); err != nil {
util.Logger.Logger.Fatalf("Cannot connect to MySQL database: %v", err)
}
}
Expand Down
6 changes: 4 additions & 2 deletions app/database/database.go
Expand Up @@ -12,12 +12,14 @@ import (
var DB *sqlx.DB

// Open creates a new connection to a MySQL database with the given credentials
func Open(username, password, db, params string) (*sqlx.DB, error) {
func Open(username, password, host, port, db, params string) (*sqlx.DB, error) {
// Connect to the given database
databaseHandle, err := sqlx.Connect("mysql", fmt.Sprintf(
"%v:%v@/%v?charset=utf8&parseTime=True&loc=Local"+params,
"%v:%v@(%v:%v)/%v?charset=utf8&parseTime=True&loc=Local"+params,
username,
password,
host,
port,
db,
))

Expand Down
7 changes: 4 additions & 3 deletions install.go
Expand Up @@ -544,9 +544,10 @@ func installApplication(location string) error {
}

// Connect to database
conn, err := database.Open(
lua.Config.GetGlobal("mysqlUser").String(),
lua.Config.GetGlobal("mysqlPass").String(),
conn, err := database.Open(lua.Config.GetGlobal("mysqlUser").String(),
lua.Config.GetGlobal("mysqlPass").String(),
lua.Config.GetGlobal("mysqlHost").String(),
lua.Config.GetGlobal("mysqlPort").String(),
lua.Config.GetGlobal("mysqlDatabase").String(),
"&multiStatements=true",
)
Expand Down

0 comments on commit 23e665d

Please sign in to comment.