Ejemplo n.º 1
0
func main() {
	dbh, err := mysql.Connect("tcp", "", "127.0.0.1:3306", "test", "test", "") // With password, user test, with database.
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	}
	dbh.Use("test")
	dbh.Query("SET NAMES utf8")
	sth := new(mysql.MySQLStatement)
	sth, err = dbh.Prepare("SELECT * FROM test WHERE id = ? OR id = ? OR id = ?")
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	}
	res, err := sth.Execute(1, 2, 3)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	}
	rows := res.FetchAllRowMap()
	fmt.Printf("Rows: %d\n", len(rows))
	fmt.Printf("%#v\n", rows)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	}

	dbh.Quit()
}
Ejemplo n.º 2
0
func (e *MysqlConnector) Open(connectionString string) bool {
	tab := strings.Split(connectionString, "/", 0)
	db := tab[len(tab)-1]
	tab2 := strings.Split(tab[2], "@", 2)
	tab = strings.Split(tab2[0], ":", 0)
	//	fmt.Println(tab)
	//	fmt.Println(tab2)
	user := tab[0]
	pass := tab[1]

	dbh, err := mysql.Connect("tcp", "", tab2[1], user, pass, "")
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	}
	e.conn = dbh
	e.conn.Use(db)
	return false
}