Skip to content

Instantly share code, notes, and snippets.

@Macagare
Created September 1, 2013 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Macagare/6403856 to your computer and use it in GitHub Desktop.
Save Macagare/6403856 to your computer and use it in GitHub Desktop.
create mysql connection and do query
package main
import (
"fmt"
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func main() {
loadData()
}
func loadData(ids []int) {
con, err := sql.Open("mysql", "user:pass@tcp(location:port)/dbname")
var id string
if err != nil {
fmt.Println("Error")
}
defer con.Close()
con.QueryRow("SELECT name as id FROM table" ).Scan(&id)
fmt.Println(id)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment