123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package main
- import (
- "database/sql"
- "fmt"
- _ "github.com/go-sql-driver/mysql"
- )
- var mysqlDb *sql.DB
- func regMysql(brand string) {
- //const mySqlUrl = "%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&loc=Local"
- url := ""
- switch brand {
- case "ugg":
- url = fmt.Sprintf("root:plmPLM0.@tcp(%s.imix7.com:13306)/uggwb?charset=utf8mb4&loc=Local", brand)
- case "hdugg":
- url = fmt.Sprintf("root:plmPLM0.@tcp(%s.imix7.com:13306)/hduggwb?charset=utf8mb4&loc=Local", brand)
- case "ecco":
- url = fmt.Sprintf("root:plmPLM0.@tcp(%s.imix7.com:13306)/weimob?charset=utf8mb4&loc=Local", brand)
- }
- if len(url) == 0 {
- panic("mysql brand error")
- }
- db, err := sql.Open("mysql", url)
- if err != nil {
- panic(err)
- }
- err = db.Ping()
- if err != nil {
- panic(err)
- }
- mysqlDb = db
- }
- type Vip struct {
- Wid int64
- Phone string
- Name string
- }
- func GetAllWid() ([]Vip, error) {
- sqlStr := `select wid,phone,name from user order by wid `
- rows, err := mysqlDb.Query(sqlStr)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
- var vips []Vip
- for rows.Next() {
- var vip Vip
- err := rows.Scan(&vip.Wid, &vip.Phone, &vip.Name)
- if err != nil {
- return nil, err
- }
- vips = append(vips, vip)
- }
- return vips, nil
- }
|