package main
import (
"fmt"
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func main() {
var sqlt string
var table string
db, err := sql.Open("mysql", "root:password@/dbname?charset=utf8")
//查询
sqlt = "SELECT tid from " + table + " where id = (SELECT max(id) FROM " + table + ");"
rows, err = db.Query(sqlt)
for rows.Next() {
err = rows.Scan(&tid)
fmt.Println(tid)
}
//插入
sqlt = "INSERT " + table + " SET tid=?,amount=?,price=?,time=?,type=?,funds=?"
stmt, _ := db.Prepare(sqlt)
stmt.Exec(v.Id, v.Volume, v.Price, v.At, v.Side, v.Funds)
//执行
db.Exec("delete from table where id = '1'")
}
标签:none