You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
950 B
Go
45 lines
950 B
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
_ "github.com/go-sql-driver/mysql"
|
|
"github.com/mccutchen/go-httpbin/db"
|
|
)
|
|
|
|
|
|
type CmIp struct {
|
|
Id string `json:"id"`
|
|
Ip string `json:"ip"`
|
|
Updatetime string `json:"updatetime"`
|
|
}
|
|
|
|
func QueryIp10() *CmIp {
|
|
DB := db.ConnectDb()
|
|
var cmip CmIp
|
|
rows, e := DB.Query("select * from cm_ip where id = 1")
|
|
if e != nil {
|
|
//errors.New("query incur error")
|
|
fmt.Println("query include error")
|
|
return &CmIp{}
|
|
}
|
|
for rows.Next() {
|
|
e := rows.Scan(&cmip.Id, &cmip.Ip, &cmip.Updatetime)
|
|
if e != nil {
|
|
fmt.Println("json.Marshal error")
|
|
return &CmIp{}
|
|
}
|
|
}
|
|
rows.Close()
|
|
db.ClosetDb(DB)
|
|
body, _ := json.Marshal(cmip)
|
|
fmt.Println(string(body))
|
|
|
|
//// 单行查询操作
|
|
//DB := db.ConnectDb()
|
|
//DB.QueryRow("select * from cm_ip where id = 1").Scan(&cmip.Id,&cmip.Ip, &cmip.Updatetime)
|
|
//body, _ := json.Marshal(cmip)
|
|
//fmt.Println(string(body))
|
|
//db.ClosetDb(DB)
|
|
return &cmip
|
|
} |