package main
import (
"database/sql"
"fmt"
)
func ConnectDB() (db *sql.DB, err error) {
dbDriver := "mysql"
dbUser := "root"
dbPass := "nilpointer.net"
dbName := "nilpointer_db"
db, err = sql.Open(dbDriver, dbUser+":"+dbPass+"@/"+dbName)
return
}
func main() {
db, err := ConnectDB()
if err != nil {
fmt.Println(err)
} else {
rows, err2 := db.Query("select min(price) as min_price from mobile")
if err2 != nil {
fmt.Println(err2)
} else {
var min_price float64
for rows.Next() {
rows.Scan(&min_price)
}
fmt.Println("min price: ", min_price)
}
}
}