Last active
August 29, 2015 14:25
-
-
Save methane/6bd60d3c42a2d7192e78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TABLE `TEST` ( | |
| `id` int(11) DEFAULT NULL | |
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |
| INSERT INTO TEST (id) VALUES (1) (2) (3); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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