Skip to content

Instantly share code, notes, and snippets.

@kkdai
Created August 29, 2014 12:16
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 kkdai/c368856da99d2aed5ef8 to your computer and use it in GitHub Desktop.
Save kkdai/c368856da99d2aed5ef8 to your computer and use it in GitHub Desktop.
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
// Create the database handle, confirm driver is present
db, _ := sql.Open("mysql", "root:password@/4image")
defer db.Close()
// Connect and check the server version
var version string
db.QueryRow("SELECT VERSION()").Scan(&version)
fmt.Println("Connected to:", version)
var name string
db.QueryRow("select cat_name from 4images_categories limit 1").Scan(&name)
fmt.Println("cat name =", name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment