Skip to content

Instantly share code, notes, and snippets.

@methane
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save methane/6bd60d3c42a2d7192e78 to your computer and use it in GitHub Desktop.

Select an option

Save methane/6bd60d3c42a2d7192e78 to your computer and use it in GitHub Desktop.
CREATE TABLE `TEST` (
`id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO TEST (id) VALUES (1) (2) (3);
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "root@tcp(localhost:3306)/test")
if err != nil {
panic(err)
}
rows, err := db.Query("SELECT `id` FROM `TEST`")
if err != nil {
panic(err)
}
for rows.Next() {
var s string
err := rows.Scan(&s)
if err != nil {
panic(err)
}
fmt.Printf("%q\n", s)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment