function q($sql, $params = array(), $c = null)
{
    if ($c == null) {
        $c = connection();
    }
    if (sizeof($params) > 0) {
        $prep = array();
        foreach ($params as $i => $v) {
            $prep[$i] = is_array($v) && isset($v["expr"]) ? $v["expr"] : (is_string($v) ? "'" . $c["conn"]->escapeString($v) . "'" : (is_bool($v) ? (int) $v : ($v === null ? "NULL" : $c["conn"]->escapeString($v))));
        }
        $res = $c["conn"]->query(lastsql(vsprintf($sql, $prep)));
    } else {
        $res = $c["conn"]->query(lastsql($sql));
    }
    if (!$res) {
        trigger_error(lastdberror($c["conn"]->lastErrorCode() . ": " . $c["conn"]->lastErrorMsg()), E_USER_WARNING);
        return $res;
    }
    return array(0, $res);
}
 function field_sort()
 {
     $list = M('model')->select();
     // dump ( $list );
     foreach ($list as $v) {
         if (empty($v['field_sort'])) {
             continue;
         }
         $field_sort = json_decode($v['field_sort'], true);
         if (!is_array($field_sort[1])) {
             continue;
         }
         $field_sort = json_encode($field_sort[1]);
         // dump ( $field_sort );
         $map['id'] = $v['id'];
         $res = M('model')->where($map)->setField('field_sort', $field_sort);
         dump($res);
         lastsql();
     }
     dump('It is over');
 }
 function save_store_license()
 {
     $config_map['name'] = 'WEIPHP_STORE_LICENSE';
     $res = M('config')->where($config_map)->setField('value', I('license'));
     dump($res);
     lastsql();
 }
 function mylove()
 {
     // ALTER TABLE `wp_prize` ADD COLUMN `token` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Token' AFTER `img`;
     // ALTER TABLE `wp_sn_code` ADD COLUMN `token` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Token' AFTER `prize_title`;
     $_token = array();
     $dao = M('prize');
     $list = $dao->select();
     foreach ($list as $v) {
         $map['id'] = $v['id'];
         $key = $v['addon'] . '_' . $v['target_id'];
         if (isset($_token[$key])) {
             $save['token'] = $_token[$key];
         } else {
             $save['token'] = $_token[$key] = M($v['addon'])->where('id=' . $v['target_id'])->getField('token');
         }
         $res = $dao->where($map)->save($save);
         dump($res);
         lastsql();
     }
     $dao = M('sn_code');
     $list = $dao->select();
     foreach ($list as $v) {
         $map['id'] = $v['id'];
         $key = $v['addon'] . '_' . $v['target_id'];
         if (isset($_token[$key])) {
             $save['token'] = $_token[$key];
         } else {
             $save['token'] = $_token[$key] = M($v['addon'])->where('id=' . $v['target_id'])->getField('token');
         }
         $res = $dao->where($map)->save($save);
         dump($res);
         lastsql();
     }
 }
 function del_data()
 {
     $res = M()->execute('DELETE FROM wp_user WHERE uid!=1');
     dump($res);
     lastsql();
     $res = M()->execute('DELETE FROM wp_manager_menu WHERE uid!=1');
     dump($res);
     lastsql();
     $res = M()->execute('DELETE FROM wp_auth_group WHERE manager_id!=0');
     dump($res);
     lastsql();
     $res = M()->execute('DELETE FROM wp_auth_group_access WHERE uid!=1');
     dump($res);
     lastsql();
     $arr = array('wp_analysis', 'wp_picture', 'wp_weixin_log', 'wp_action_log', 'wp_weixin_message', 'wp_sports', 'wp_shop_order_log', 'wp_vote_option', 'wp_lzwg_coupon_sn', 'wp_guess_option', 'wp_lzwg_log', 'wp_message', 'wp_file', 'wp_lzwg_vote_option', 'wp_action', 'wp_sports_team', 'wp_shop_goods', 'wp_xydzp_jplist', 'wp_shop_goods_category', 'wp_lzwg_coupon_receive', 'wp_coupon_shop_link', 'wp_business_card_collect', 'wp_lzwg_coupon', 'wp_lzwg_activities_vote');
     foreach ($arr as $t) {
         $res = M()->execute('DELETE FROM ' . $t);
         dump($res);
         lastsql();
         $res = M()->execute('ALTER TABLE ' . $t . ' AUTO_INCREMENT=1');
         dump($res);
         lastsql();
     }
     $tables = "'wp_user','wp_manager_menu','wp_auth_group','wp_credit_config','wp_auth_group_access'";
     $sql = "SELECT TABLE_NAME as t,COLUMN_NAME as f FROM information_schema.`COLUMNS` WHERE TABLE_SCHEMA='weiphp3.0' AND COLUMN_NAME in ('uid','manager_id','token') AND TABLE_NAME not in ({$tables})";
     $list = M()->query($sql);
     foreach ($list as $vo) {
         $res = M()->execute('DELETE FROM ' . $vo['t']);
         dump($res);
         lastsql();
         $res = M()->execute('ALTER TABLE ' . $vo['t'] . ' AUTO_INCREMENT=1');
         dump($res);
         lastsql();
     }
     $res = M()->execute('update wp_user set is_init=0 where uid=1');
     dump($res);
     lastsql();
 }
 function del_data()
 {
     $res = M()->execute('DELETE FROM wp_user WHERE uid!=1');
     dump($res);
     lastsql();
     $res = M()->execute('DELETE FROM wp_manager_menu WHERE uid!=1');
     dump($res);
     lastsql();
     $res = M()->execute('DELETE FROM wp_auth_group WHERE manager_id!=0');
     dump($res);
     lastsql();
     $res = M()->execute('DELETE FROM wp_auth_group_access WHERE uid!=1');
     dump($res);
     lastsql();
     $arr = array();
     foreach ($arr as $t) {
         $res = M()->execute('DELETE FROM ' . $t);
         dump($res);
         lastsql();
         $res = M()->execute('ALTER TABLE ' . $t . ' AUTO_INCREMENT=1');
         dump($res);
         lastsql();
     }
     $tables = "'wp_user','wp_manager_menu','wp_auth_group','wp_credit_config','wp_auth_group_access'";
     $sql = "SELECT TABLE_NAME as t,COLUMN_NAME as f FROM information_schema.`COLUMNS` WHERE TABLE_SCHEMA='weiphp3.0' AND COLUMN_NAME in ('uid','manager_id','token') AND TABLE_NAME not in ({$tables})";
     $list = M()->query($sql);
     foreach ($list as $vo) {
         $res = M()->execute('DELETE FROM ' . $vo['t']);
         dump($res);
         lastsql();
         $res = M()->execute('ALTER TABLE ' . $vo['t'] . ' AUTO_INCREMENT=1');
         dump($res);
         lastsql();
     }
     $res = M()->execute('update wp_user set is_init=0 where uid=1');
     dump($res);
     lastsql();
 }