func (c *Conn) Begin() (mysql.Transaction, error) {
	c.lock()
	tr := Transaction{
		&Conn{Conn: c.Conn, mutex: new(sync.Mutex)},
		c,
	}
	_, err := c.Conn.Start("START TRANSACTION")
	if err != nil {
		c.unlock()
		return nil, err
	}
	return &tr, nil
}
Begins a new transaction. No any other thread can send command on this
connection until Commit or Rollback will be called.
Periodical pinging the server is disabled during transaction.
package thrsafe
import (
	"io"
	"sync"
	"time"
	"github.com/ziutek/mymysql/mysql"
	_ "github.com/ziutek/mymysql/native"
)
type Conn struct {
	mysql.Conn
	mutex *sync.Mutex
	stopPinger chan struct{}
	lastUsed   time.Time
}
func (c *Conn) lock() {
	c.mutex.Lock()
}
func (c *Conn) unlock() {
	c.lastUsed = time.Now()
	c.mutex.Unlock()
}
type Result struct {
	mysql.Result
	conn *Conn
}
type Stmt struct {
	mysql.Stmt
	conn *Conn
}
type Transaction struct {
	*Conn
	conn *Conn
}
func New(proto, laddr, raddr, user, passwd string, db ...string) mysql.Conn {
	return &Conn{
		Conn:  orgNew(proto, laddr, raddr, user, passwd, db...),
		mutex: new(sync.Mutex),
	}
}
func (c *Conn) Clone() mysql.Conn {
	return &Conn{
		Conn:  c.Conn.Clone(),
		mutex: new(sync.Mutex),
	}
}
func (c *Conn) pinger() {
	const to = 60 * time.Second
	sleep := to
	for {
		timer := time.After(sleep)
		select {
		case <-c.stopPinger:
			return
		case t := <-timer:
			c.mutex.Lock()
			lastUsed := c.lastUsed
			c.mutex.Unlock()
			sleep := to - t.Sub(lastUsed)
			if sleep <= 0 {
				if c.Ping() != nil {
					return
				}
				sleep = to
			}
		}
	}
}
func (c *Conn) Connect() error {
	c.lock()
	defer c.unlock()
	c.stopPinger = make(chan struct{})
	go c.pinger()
	return c.Conn.Connect()
}
func (c *Conn) Close() error {
	close(c.stopPinger)  
	c.lock()
	defer c.unlock()
	return c.Conn.Close()
}
func (c *Conn) Reconnect() error {
	c.lock()
	defer c.unlock()
	if c.stopPinger == nil {
		go c.pinger()
	}
	return c.Conn.Reconnect()
}
func (c *Conn) Use(dbname string) error {
	c.lock()
	defer c.unlock()
	return c.Conn.Use(dbname)
}
func (c *Conn) Start(sql string, params ...interface{}) (mysql.Result, error) {
	c.lock()
	res, err := c.Conn.Start(sql, params...)
	if err != nil {
		c.unlock()
		return nil, err
	}
	if res.StatusOnly() && !res.MoreResults() {
		c.unlock()
	}
	return &Result{Result: res, conn: c}, err
}
func (c *Conn) Status() mysql.ConnStatus {
	c.lock()
	defer c.unlock()
	return c.Conn.Status()
}
func (c *Conn) Escape(txt string) string {
	return mysql.Escape(c, txt)
}
func (res *Result) ScanRow(row mysql.Row) error {
	err := res.Result.ScanRow(row)
	if err == nil {
		return nil
	}
	if err == mysql.ErrReadAfterEOR {
		return err
	}
	if err != io.EOF || !res.StatusOnly() && !res.MoreResults() {
		res.conn.unlock()
	}
	return err
}
func (res *Result) GetRow() (mysql.Row, error) {
	return mysql.GetRow(res)
}
func (res *Result) NextResult() (mysql.Result, error) {
	next, err := res.Result.NextResult()
	if err != nil {
		return nil, err
	}
	if next == nil {
		return nil, nil
	}
	if next.StatusOnly() && !next.MoreResults() {
		res.conn.unlock()
	}
	return &Result{next, res.conn}, nil
}
func (c *Conn) Ping() error {
	c.lock()
	defer c.unlock()
	return c.Conn.Ping()
}
func (c *Conn) Prepare(sql string) (mysql.Stmt, error) {
	c.lock()
	defer c.unlock()
	stmt, err := c.Conn.Prepare(sql)
	if err != nil {
		return nil, err
	}
	return &Stmt{Stmt: stmt, conn: c}, nil
}
func (stmt *Stmt) Run(params ...interface{}) (mysql.Result, error) {
	stmt.conn.lock()
	res, err := stmt.Stmt.Run(params...)
	if err != nil {
		stmt.conn.unlock()
		return nil, err
	}
	if res.StatusOnly() && !res.MoreResults() {
		stmt.conn.unlock()
	}
	return &Result{Result: res, conn: stmt.conn}, nil
}
func (stmt *Stmt) Delete() error {
	stmt.conn.lock()
	defer stmt.conn.unlock()
	return stmt.Stmt.Delete()
}
func (stmt *Stmt) Reset() error {
	stmt.conn.lock()
	defer stmt.conn.unlock()
	return stmt.Stmt.Reset()
}
func (stmt *Stmt) SendLongData(pnum int, data interface{}, pkt_size int) error {
	stmt.conn.lock()
	defer stmt.conn.unlock()
	return stmt.Stmt.SendLongData(pnum, data, pkt_size)
}
func (c *Conn) Query(sql string, params ...interface{}) ([]mysql.Row, mysql.Result, error) {
	return mysql.Query(c, sql, params...)
}
func (my *Conn) QueryFirst(sql string, params ...interface{}) (mysql.Row, mysql.Result, error) {
	return mysql.QueryFirst(my, sql, params...)
}
func (my *Conn) QueryLast(sql string, params ...interface{}) (mysql.Row, mysql.Result, error) {
	return mysql.QueryLast(my, sql, params...)
}
func (stmt *Stmt) Exec(params ...interface{}) ([]mysql.Row, mysql.Result, error) {
	return mysql.Exec(stmt, params...)
}
func (stmt *Stmt) ExecFirst(params ...interface{}) (mysql.Row, mysql.Result, error) {
	return mysql.ExecFirst(stmt, params...)
}
func (stmt *Stmt) ExecLast(params ...interface{}) (mysql.Row, mysql.Result, error) {
	return mysql.ExecLast(stmt, params...)
}
func (res *Result) End() error {
	return mysql.End(res)
}
func (res *Result) GetFirstRow() (mysql.Row, error) {
	return mysql.GetFirstRow(res)
}
func (res *Result) GetLastRow() (mysql.Row, error) {
	return mysql.GetLastRow(res)
}
func (res *Result) GetRows() ([]mysql.Row, error) {
	return mysql.GetRows(res)
}