func (m xxxstruct) insertxxx() (bool,string){
sqlquery :="insert into tables_name(id,name,email,content,) values(%v,%v,%v,%v)"
sqlquery =fmt.Sprintf(sqlquery,m.id,m.name,m.email,m.content)
ok,desc :=queryexecmysql(sqlquery)
if ok {
return false,desc
}
return true,"ok"
}
func queryexecmysql(parmam string)(bool string){
o :=orm.NewOrm()
o.Using("deafult")
_,err :=o.Raw(parmam).Exec()
if err !=nil ||err ==orm.ErrNORow{
log.Error(err)
return false,"error:"+err.Error()
}
return true,"ok"
}
本文出自 “东神要一打五” 博客,谢绝转载!
原文:http://gdutccd.blog.51cto.com/9271664/1769818