zoukankan      html  css  js  c++  java
  • model

    
    package main
    
    import (
    	"fmt"
    	_ "github.com/go-sql-driver/mysql"
    	"github.com/jmoiron/sqlx"
    )
    
    type Users struct {
    	ID   int    `db:"id"`
    	Name string `db:"name"`
    	Password      string `db:"password"`
    	Email    string `db:"email"`
    }
    
    type Place struct {
    	Country string `db:"country"`
    	City    string `db:"city"`
    	TelCode int    `db:"telcode"`
    }
    
    var Db2 *sqlx.DB
    
    func init() {
    
    	database, err := sqlx.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/book")
    	if err != nil {
    		fmt.Println("open mysql failed,", err)
    		return
    	}
    
    	Db2 = database
    }
    
    func CheckErr(err error){
    	if err != nil{
    		panic(err)
    	}
    }
    
    func Query()  {
    	var person []Users
    	err := Db2.Select(&person, "select id, name, password, email from users where id=?", 1)
    	CheckErr(err)
    	fmt.Println(person)
    }
    
    func main() {
    
    	//_, err := Db2.Exec("", 1)
    	//if err != nil {
    	//	fmt.Println("exec failed, ", err)
    	//	return
    	//}
    	Query()
    	fmt.Println("delete succ")
    }
    
    
  • 相关阅读:
    Markdown学习
    二叉树的最近公共祖先
    javaCompiler简析
    自定义类加载器
    聚合和组合的区别
    拓扑排序
    C++ map和unordered_map
    静态文件加载路径
    文件上传
    jackson
  • 原文地址:https://www.cnblogs.com/lajiao/p/10906312.html
Copyright © 2011-2022 走看看