• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang mysql.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/ziutek/mymysql/mysql.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: get_id

func get_id() {
	db := mysql.New("tcp", "", "183.60.126.26:3306", user, pass, dbname)
	db1 := mysql.New("tcp", "", "183.60.126.26:3306", user, pass, dbname)

	err := db.Connect()
	if err != nil {
		panic(err)
	}
	defer db.Close()

	err = db1.Connect()
	defer db1.Close()

	rows, _, err := db.Query("select bag_id,stuff_id from player_bag b, paladin p where player_id = %d and b.stuff_id=p.paladin_id and is_active=0", 26559)
	if err != nil {
		panic(err)
	}

	for _, row := range rows {
		for _, col := range row {
			if col == nil {
				// col has NULL value
			} else {
				// Do something with text in col (type []byte)
			}
		}

		bag_id := row.Int(0)
		stuff_id := row.Int(1)
		fmt.Printf("%d, %d\n", bag_id, stuff_id)

		//del(db, bag_id, stuff_id);
	}
}
开发者ID:bonly,项目名称:exercise,代码行数:34,代码来源:20100812_del_paladin.go


示例2: Open

// Open new connection. The uri need to have the following syntax:
//
//   [PROTOCOL_SPECFIIC*]DBNAME/USER/PASSWD
//
// where protocol spercific part may be empty (this means connection to
// local server using default protocol). Currently possible forms:
//   DBNAME/USER/PASSWD
//   unix:SOCKPATH*DBNAME/USER/PASSWD
//   tcp:ADDR*DBNAME/USER/PASSWD
func (d *Driver) Open(uri string) (driver.Conn, error) {
	pd := strings.SplitN(uri, "*", 2)
	if len(pd) == 2 {
		// Parse protocol part of URI
		p := strings.SplitN(pd[0], ":", 2)
		if len(p) != 2 {
			return nil, errors.New("Wrong protocol part of URI")
		}
		d.proto = p[0]
		d.raddr = p[1]
		// Remove protocol part
		pd = pd[1:]
	}
	// Parse database part of URI
	dup := strings.SplitN(pd[0], "/", 3)
	if len(dup) != 3 {
		return nil, errors.New("Wrong database part of URI")
	}
	d.db = dup[0]
	d.user = dup[1]
	d.passwd = dup[2]

	// Establish the connection
	c := conn{mysql.New(d.proto, d.laddr, d.raddr, d.user, d.passwd, d.db)}
	for _, q := range d.initCmds {
		c.my.Register(q) // Register initialisation commands
	}
	if err := c.my.Connect(); err != nil {
		return nil, errFilter(err)
	}
	return &c, nil
}
开发者ID:qingshao,项目名称:mymysql,代码行数:41,代码来源:driver.go


示例3: show_count

func show_count(w http.ResponseWriter, r *http.Request) {
	log.Println("process count request")
	srv1.TimeNow = time.Now()

	db1 := mysql.New("tcp", "", *(srv1.addr), *(srv1.user), *(srv1.pass), *(srv1.dbname))
	err := db1.Connect()
	defer db1.Close()
	if err != nil {
		panic(err)
	}
	_, _, _ = db1.Query("set wait_timeout = 3600")
	_, _, _ = db1.Query("set interactive_timeout = 3600")

	//	     fmt.Fprintf(w, player_page,
	//	                 get_all_reg(&db1),
	//	                 pve_online_5(&db1),
	//	                 get_login_30(&db1));

	srv1.D帐户数 = get_all_reg(&db1)
	srv1.D角色数 = get_player(&db1)
	srv1.D活跃数 = pve_online_5(&db1)
	srv1.D登录_30 = get_login_30(&db1)
	srv1.D登录_60 = get_login_60(&db1)
	get_level_count(&db1, &srv1)

	log.Println("parse file: ", *cssFile)
	tmp, _ := template.ParseFiles(*cssFile)
	tmp.Execute(w, srv1)
}
开发者ID:bonly,项目名称:exercise,代码行数:29,代码来源:20100909_web_template.go


示例4: FetchMetrics

// FetchMetrics interface for mackerelplugin
func (m MySQLPlugin) FetchMetrics() (map[string]interface{}, error) {
	db := mysql.New("tcp", "", m.Target, m.Username, m.Password, "")
	err := db.Connect()
	if err != nil {
		log.Fatalln("FetchMetrics (DB Connect): ", err)
		return nil, err
	}
	defer db.Close()

	stat := make(map[string]float64)
	m.fetchShowStatus(db, stat)

	if m.DisableInnoDB != true {
		m.fetchShowInnodbStatus(db, stat)
		m.fetchShowVariables(db, stat)
	}

	m.fetchShowSlaveStatus(db, stat)

	statRet := make(map[string]interface{})
	for key, value := range stat {
		statRet[key] = value
	}

	return statRet, err
}
开发者ID:naokibtn,项目名称:mackerel-agent-plugins,代码行数:27,代码来源:mysql.go


示例5: main

func main() {
	user := "root"
	pass := "root"
	dbname := "test"

	db := mysql.New("tcp", "", "127.0.0.1:3306", user, pass, dbname)

	err := db.Connect()
	if err != nil {
		panic(err)
	}

	rows, res, err := db.Query("select 'hello world' as  FirstColumn,22 as SecondColumn limit  %d", 20)
	if err != nil {
		panic(err)
	}

	for _, row := range rows {
		for _, col := range row {
			if col == nil {
				// col has NULL value
			} else {
				// Do something with text in col (type []byte)
			}
		}

		// You may get values by column name
		first := res.Map("FirstColumn")
		//second := res.Map("SecondColumn")
		fmt.Printf(row.Str(first))
	}
}
开发者ID:ludovicdeluna,项目名称:go,代码行数:32,代码来源:mysql.go


示例6: getAdmin

func getAdmin(adminid int) (string, string) {
	db := mysql.New("tcp", "", "127.0.0.1:3306", dbusername, dbpassowrd, dbname)

	err := db.Connect()
	if err != nil {
		log.Panic(err)
	}
	defer db.Close()

	rows, res, err := db.Query("select * from user where uid=%d", adminid)
	if err != nil {
		log.Panic(err)
	}

	if len(rows) < 1 {
		log.Panic("rows error")
	}

	row := rows[0]

	first := res.Map("username")
	second := res.Map("password")

	username, password := row.Str(first), row.Str(second)
	return username, password
}
开发者ID:jeffreymu,项目名称:golang_demo_1,代码行数:26,代码来源:mymysql.go


示例7: get_reg

func get_reg() (int, int) {
	db := mysql.New("tcp", "", "117.135.154.58:3306", user, pass, dbname)
	err := db.Connect()
	var ret_all = 0
	var ret_player = 0
	if err != nil {
		panic(err)
		return ret_all, ret_player
	}
	defer db.Close()
	_, _, _ = db.Query("set wait_timeout = 3600")
	_, _, _ = db.Query("set interactive_timeout = 3600")

	rows, _, err := db.Query("select count(customer_id)-54 from customer.customer")
	if err != nil {
		panic(err)
	}
	for _, row := range rows {
		ret_all = row.Int(0)
	}
	rows, _, err = db.Query("select count(player_id) from player where vip>=1 and player_id>27048")
	if err != nil {
		panic(err)
	}
	for _, row := range rows {
		ret_player = row.Int(0)
	}
	return ret_all, ret_player
}
开发者ID:bonly,项目名称:exercise,代码行数:29,代码来源:20100827_data.go


示例8: FetchData

func FetchData(m *model.MysqlIns, socketfile string, cfg *base.Cfg) (err error) {
	defer func() {
		MysqlAlive(cfg, m, err == nil)
	}()

	//db := mysql.New("tcp", "", fmt.Sprintf("%s:%d", m.Host, m.Port), cfg.User, cfg.Pass)
	db := mysql.New("unix", "", socketfile, cfg.User, cfg.Pass)
	db.SetTimeout(500 * time.Millisecond)
	if err = db.Connect(); err != nil {
		return
	}
	defer db.Close()

	data := make([]*model.MetaData, 0)
	threadNums, err := collect.ProcessNum(db, cfg)
	if err != nil {
		return
	}
	data = append(data, threadNums)
	slaveState, err := collect.SlaveStatus(db, cfg)
	if err != nil {
		return
	}
	data = append(data, slaveState...)

	msg, err := SendData(data, cfg)
	if err != nil {
		return
	}
	log.Infof("Send response %v: %s", m, string(msg))
	return
}
开发者ID:onlymellb,项目名称:mysql-monitor,代码行数:32,代码来源:fetchData.go


示例9: show_level

func show_level(w http.ResponseWriter, r *http.Request) {
	log.Println("process level request")
	nav(w)
	db1 := mysql.New("tcp", "", *(srv1.addr), *(srv1.user), *(srv1.pass), *(srv1.dbname))
	err := db1.Connect()
	defer db1.Close()
	if err != nil {
		panic(err)
	}
	_, _, _ = db1.Query("set wait_timeout = 3600")
	_, _, _ = db1.Query("set interactive_timeout = 3600")

	get_level_count(&db1, &srv1)

	fmt.Fprintf(w, `<br>`)
	level_tmp := template.New("")
	level_tmp.Parse(`
	  <table width="307" height="414" border="1" cellspacing="0" bordercolor="#333366">
	  <tr>
		  <td><span class="style3">等级</span></td>
		  <td width="88"><span class="style5">  人数 &nbsp;</span></td>
		</tr>
	  {{range $k,$v := .D级别}}
	  <tr>
		  <td><span class="style3">级别 {{$k}}0-{{$k}}9 级</span></td>
		  <td width="88"><span class="style5">  {{$v}} &nbsp;</span></td>
		</tr>
		{{end}}
	  </table>
	`)
	level_tmp.Execute(w, srv1)
}
开发者ID:bonly,项目名称:exercise,代码行数:32,代码来源:20100914_web.go


示例10: main

// MAIN
func main() {
	var err error
	var w io.Writer

	parseCommandLine()
	readConfigFile()

	raddr := fmt.Sprintf("%s:%d", hostname, port)
	db := mysql.New("tcp", "", raddr, username, password, database)
	db.Register("SET NAMES utf8")
	err = db.Connect()
	checkError(err)

	if *output == "" {
		w = os.Stdout
	} else {
		w, err = os.Create(*output)
		checkError(err)
	}

	fmt.Fprintf(w, "SET NAMES utf8;\n")
	fmt.Fprintf(w, "SET FOREIGN_KEY_CHECKS = 0;\n")

	tables := getTables(db)
	for _, table := range tables {
		dumpCreateTable(w, db, table)
		dumpTableData(w, db, table)
	}

	fmt.Fprintf(w, "SET FOREIGN_KEY_CHECKS = 1;\n")
}
开发者ID:sirishkumar,项目名称:mysqlsuperdump,代码行数:32,代码来源:mysqlsuperdump.go


示例11: dbConn

func dbConn(obj_feed chan PerformanceStamp) {
	user := "root"
	pass := ""
	dbname := "multicdn"
	//proto  := "unix"
	//addr   := "/var/run/mysqld/mysqld.sock"
	proto := "tcp"
	addr := "127.0.0.1:3306"

	db := mysql.New(proto, "", addr, user, pass, dbname)

	fmt.Printf("Connect to %s:%s... ", proto, addr)

	checkError(db.Connect())
	printOK()

	go func() {
		idx := 0
		for obj := range obj_feed {
			db.Query("insert cdn_logs values ('%s', '%s', '%s', '%s')", obj.ts, obj.cdn, obj.ip, obj.url)
			idx++

			if idx%1000 == 0 {
				fmt.Printf("%d. records saved\n", idx)
			}
		}
	}()
}
开发者ID:spil-bahadir,项目名称:learn-go,代码行数:28,代码来源:log_parser_db.go


示例12: zip_around_10_miles

func zip_around_10_miles(cur_zip string, limit int) []string {
	if cur_zip == "" {
		return nil
	}
	config, _ := toml.LoadFile("config.toml")
	mysql_user_name, _ := config.Get("mysql_user_name").(string)
	mysql_password, _ := config.Get("mysql_password").(string)
	mysql_db_name, _ := config.Get("mysql_db_name").(string)
	mysql_url, _ := config.Get("mysql_url").(string)

	db := mysql.New("tcp", "", mysql_url, mysql_user_name, mysql_password, mysql_db_name)
	err := db.Connect()
	if err != nil {
		panic(err)
	}
	rows, _, err := db.Query("SELECT `zip_distance`.* FROM `zip_distance` WHERE `zip_distance`.`PrimaryZip` = " + cur_zip + " LIMIT 1")
	if err != nil {
		panic(err)
	}
	var zips string
	for _, row := range rows {
		val1 := row[2].([]byte)
		row = row
		zips = string(val1)
	}
	return strings.Split(zips, ",")
}
开发者ID:kodgiresuhas,项目名称:go_api_sample,代码行数:27,代码来源:go_api_sample.go


示例13: Open

// Establish a connection using URI of following syntax:
//   DBNAME/USER/PASSWD
//   unix:SOCKPATH*DBNAME/USER/PASSWD
//   tcp:ADDR*DBNAME/USER/PASSWD
func (d *drv) Open(uri string) (driver.Conn, error) {
	pd := strings.SplitN(uri, "*", 2)
	if len(pd) == 2 {
		// Parse protocol part of URI
		p := strings.SplitN(pd[0], ":", 2)
		if len(p) != 2 {
			return nil, errors.New("Wrong protocol part of URI")
		}
		d.proto = p[0]
		d.raddr = p[1]
		// Remove protocol part
		pd = pd[1:]
	}
	// Parse database part of URI
	dup := strings.SplitN(pd[0], "/", 3)
	if len(dup) != 3 {
		return nil, errors.New("Wrong database part of URI")
	}
	d.db = dup[0]
	d.user = dup[1]
	d.passwd = dup[2]

	// Establish the connection
	mc := mysql.New(d.proto, d.laddr, d.raddr, d.user, d.passwd, d.db)
	c := conn{mc, make(map[string]driver.Stmt)}
	if err := c.my.Connect(); err != nil {
		return nil, err
	}
	return &c, nil
}
开发者ID:coopernurse,项目名称:mymysql,代码行数:34,代码来源:driver.go


示例14: checkUptime

func checkUptime() *checkers.Checker {
	opts := connectionOpts{}
	psr := flags.NewParser(&opts, flags.Default)
	_, err := psr.Parse()
	if err != nil {
		os.Exit(1)
	}

	db := mysql.New("tcp", "", fmt.Sprintf("%s:%s", opts.mysqlSetting.Host, opts.mysqlSetting.Port), opts.mysqlSetting.User, opts.mysqlSetting.Pass, "")
	err = db.Connect()
	if err != nil {
		return checkers.Critical("couldn't connect DB")
	}
	defer db.Close()

	rows, res, err := db.Query("SHOW GLOBAL STATUS LIKE 'Uptime'")
	if err != nil {
		return checkers.Critical("couldn't execute query")
	}

	idxValue := res.Map("Value")
	Uptime := rows[0].Int64(idxValue)

	if opts.Crit > 0 && Uptime < opts.Crit {
		return checkers.Critical(fmt.Sprintf("up %s < %s", uptime2str(Uptime), uptime2str(opts.Crit)))
	} else if opts.Warn > 0 && Uptime < opts.Warn {
		return checkers.Warning(fmt.Sprintf("up %s < %s", uptime2str(Uptime), uptime2str(opts.Warn)))
	}
	return checkers.Ok(fmt.Sprintf("up %s", uptime2str(Uptime)))
}
开发者ID:kazeburo,项目名称:go-check-mysql-uptime,代码行数:30,代码来源:check-mysql-uptime.go


示例15: CreateCon

func CreateCon(addr string, user string, passwd string, dbname string) (con mysql.Conn) {
	proto := "tcp"
	con = mysql.New(proto, "", addr, user, passwd, dbname)
	fmt.Printf("Connect to %s:%s... ", proto, addr)
	CheckError(con.Connect())
	PrintOK()
	return
}
开发者ID:yankai913,项目名称:go-login-demo,代码行数:8,代码来源:dao.go


示例16: ConnectToDb

func ConnectToDb(cfg DBConfig) mysql.Conn {
	db := mysql.New("tcp", "", cfg.Addr, cfg.User, cfg.Passward, cfg.DBName)
	db.Register("set names utf8")

	fmt.Printf("Connect to %s[%s]... ", cfg.Addr, cfg.DBName)
	checkError(db.Connect())
	return db
}
开发者ID:zkbcoder,项目名称:gosrc,代码行数:8,代码来源:main.go


示例17: LoginAction

func (this *AjaxController) LoginAction(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("content-type", "application/json")

	err := r.ParseForm() //未调用此函数前,r.Form是空map
	if err != nil {
		OutputJson(w, 0, "参数错误", nil)
		return
	}
	fmt.Printf("参数:%v\n", r.Form)

	admin_name := r.FormValue("admin_name")
	admin_pass := r.FormValue("admin_pass")
	fmt.Printf("admin_name:%s admin_pass:%s\n", admin_name, admin_pass)

	if admin_name == "" || admin_pass == "" {
		OutputJson(w, 0, "param error", nil)
		return
	}

	db := mysql.New("tcp", "", "127.0.0.1:3306", "root", "", "webserver")
	if err := db.Connect(); err != nil {
		OutputJson(w, 0, "database connect error", nil)
		return
	}
	defer db.Close()

	rows, res, err := db.Query("select * from user where admin_name='%s'", admin_name)
	if err != nil {
		OutputJson(w, 0, "db read failed", nil)
		return
	}

	if len(rows) == 0 {
		OutputJson(w, 1, "find no user", nil)
		return
	}

	for _, row := range rows {
		fmt.Printf("%d %s %s\n", row.Int(0), row.Str(1), row.Str(2))
	}

	fmt.Printf("data :%v res:%v\n", rows, res)
	name := res.Map("admin_password")
	admin_pass_db := rows[0].Str(name)

	if admin_pass_db != admin_pass {
		OutputJson(w, 0, "passwd error", nil)
		return
	}

	//存入cookie,使用cookie存储
	cookie := http.Cookie{Name: "admin_name", Value: rows[0].Str(res.Map("admin_name")), Path: "/"}
	http.SetCookie(w, &cookie)

	OutputJson(w, 1, "operate success", nil)
	return
}
开发者ID:yylover,项目名称:programe,代码行数:57,代码来源:AjaxController.go


示例18: crack

func (slef *ScanMysql) crack(host, user, pass, port, dbname string) (bool, *mysql.Conn) {
	db := mysql.New("tcp", "", host+":"+port, user, pass, dbname)
	db.SetTimeout(4 * time.Second)
	err := db.Connect()
	if err != nil {
		db.Close()
		return false, nil
	}
	return true, &db
}
开发者ID:sdgdsffdsfff,项目名称:mysqlfuzz,代码行数:10,代码来源:1.go


示例19: CreateConnection

// CreateConnection creates a connection to the database
func CreateConnection(host, port, user, pass, name string) *mysql.Conn {
	d := mysql.New("tcp", "", host+":"+port, user, pass, name)

	err := d.Connect()

	if err != nil {
		log.Fatal(err)
	}

	return &d
}
开发者ID:Chabare,项目名称:SQLGolang,代码行数:12,代码来源:connection.go


示例20: Connect

func Connect() z_mysql.Conn {
	//Set up database connection
	db := z_mysql.New("tcp", "", "127.0.0.1:3306", "root", "rootroot", "gps")
	err := db.Connect()
	if err != nil {
		fmt.Println("ERROR CONNECTING:", err)
		panic(err)
	}

	return db
}
开发者ID:pleskac,项目名称:SpotLocator,代码行数:11,代码来源:generics.go



注:本文中的github.com/ziutek/mymysql/mysql.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang mysql.Conn类代码示例发布时间:2022-05-28
下一篇:
Golang autorc.New函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap