Skip to content

Query方法

Tuuz edited this page Jun 20, 2022 · 2 revisions

使用query方法的时候,请务必使用"?"作为占位符,不可以把变量写入到语句中!!!

另外仅推荐在复杂语句中使用query方法,避免程序后期出现难维护的问题

func Api_count_iid_groupByLocation_byHid(hid interface{}) int64 {
	db := tuuz.Db().Table(Table)
	ret, err := db.Query("SELECT count(*) as count FROM (SELECT * FROM `tablename` WHERE `hid` = ?  and is_del=0 GROUP BY province,city,district) as b limit 1", hid)
	if err != nil {
		Log.Dbrr(err, tuuz.FUNCTION_ALL())
		return 0
	} else {
		if ret[0] != nil {
			return ret[0]["count"].(int64)
		} else {
			return 0
		}
	}
}