Go语言Mysql简单使用.
2018-07-20 来源:open-open
查询: package main import ( "database/sql" "fmt" _ "github.com/go-sql-driver/mysql" "time" ) func main() { con, _ := sql.Open("mysql", "root:123456@tcp(localhost:3316)/mysql") defer con.Close() go query(con) time.Sleep(1e9) } func query(con *sql.DB) { Q, _ := con.Prepare("select user,host,password from user where user = ? and host = ?") defer Q.Close() var x, y, z string defer func() { if e := recover(); e != nil { fmt.Println(e) } }() d, _ := Q.Query("root", "127.0.0.1") for d.Next() { d.Scan(&x, &y, &z) fmt.Println(z, y, z) } }
新建:
package main import ( "database/sql" //"fmt" _ "github.com/go-sql-driver/mysql" //"time" ) func main() { con, _ := sql.Open("mysql", "root:123456@tcp(localhost:3316)/test") defer con.Close() P, _ := con.Prepare("CREATE TABLE Test (id int not null AUTO_INCREMENT PRIMARY KEY,name varchar(20) not null)") defer P.Close() P.Exec() }
标签: Mysql
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:Android获取本地图片并显示
最新资讯
热门推荐