ctdo.de/database.go

40 lines
850 B
Go
Raw Normal View History

package main
import (
"database/sql"
2023-01-29 14:39:38 +00:00
"strings"
2023-01-28 17:45:48 +00:00
_ "github.com/go-sql-driver/mysql"
)
func dbConnect(username string, password string, address string, port string, database string) *sql.DB {
db, err := sql.Open("mysql", username+":"+password+"@tcp("+address+":"+port+")/"+database)
errorPanic(err)
return db
}
func dbClose(database *sql.DB) {
database.Close()
}
func dbQuerry(database *sql.DB, sqlCode string) *sql.Rows {
2023-01-28 18:04:26 +00:00
results, err := database.Query(sqlCode)
errorPanic(err)
return results
}
2023-01-28 18:52:41 +00:00
func ctdoConnect() *sql.DB {
dbValues := readDatabaseYML()
return dbConnect(dbValues.username, dbValues.password, dbValues.address, dbValues.port, dbValues.database)
}
2023-01-29 14:39:38 +00:00
func sqlClean(sqlString string) string {
sqlString = strings.ReplaceAll(sqlString, "'", "")
sqlString = strings.ReplaceAll(sqlString, "\"", "")
return sqlString
}