Answer the question
In order to leave comments, you need to log in
How to declare the err variable in Go when calling sql.Open if the db variable is global?
Here's how to track connection errors in such a situation?
var db *sql.DB
func connectDB() {
db, _ = sql.Open("mysql", "[email protected]/dbname")
}
Answer the question
In order to leave comments, you need to log in
var db *sql.DB
func connectDB() {
var err error
db, err = sql.Open("mysql", "[email protected]/dbname")
}
var db *sql.DB
func connectDB() error {
var err error
if db, err = sql.Open("mysql", "[email protected]/dbname"); err != nil {
return err
}
var db *sql.DB
func connectDB() (err error) {
db, err = sql.Open("mysql", "[email protected]/dbname")
return
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question