29 lines
531 B
Go
29 lines
531 B
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
)
|
|
|
|
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)
|
|
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
return db
|
|
}
|
|
|
|
func dbClose(database *sql.DB) {
|
|
database.Close()
|
|
}
|
|
|
|
func dbQuerry(database *sql.DB, sqlCode string) *sql.Rows {
|
|
results, err := database.Query("SELECT id, name FROM tags")
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
return results
|
|
}
|