未登录

Drawsnake 通行证

查看: 105|回复: 0

[原创] DSRC快速查询辅助函数

[复制链接]

管理员

是叶子,还是旅行的风

人气
0
注册时间
2024-7-19
最后登录
2025-2-3
发表于 2024-12-12 00:27:46 | 显示全部楼层 |阅读模式
Discuz技巧
适用版本: DX早期版本 DX3.4 DX3.5 
技巧类型: 二开辅助
小时空Discuz教程可能涉及的数据库快速查询函数,请根据需要自行引用。
DSRC 即 DrawSnakeRunCore,是小时空DISCUZ及THINKPHP框架中二次封装的核心函数。本文仅罗列DSRC的Discuz版的部分代码。

  1. /*请求数据列表*/
  2. if(!function_exists('rc_getlist')){
  3.     function rc_getlist($table,$con='',$order='',$page='1',$pagesize='999'){
  4.         $page = intval($page);
  5.         $page = ($page<1)?1:$page;
  6.         $start = $pagesize * ($page-1);
  7.         if($con){
  8.             $con =" WHERE ".$con;
  9.         }
  10.         if($order){
  11.             $order =" ORDER BY ".$order;
  12.         }
  13.         $result = DB::fetch_all("SELECT * FROM ".DB::table($table).$con.$order." LIMIT ".$start.",".$pagesize);
  14.         return $result;
  15.     }
  16. }

  17. /*请求数据数量*/
  18. if(!function_exists('rc_getcount')){
  19.     function rc_getcount($table,$con='',$format=''){
  20.         if($con){
  21.             $con =" WHERE ".$con;
  22.         }
  23.         $result = DB::fetch_first("SELECT COUNT(*) AS num FROM ".DB::table($table).$con);
  24.         if($format=='w'){
  25.             if($result['num']>=10000) {
  26.                 $result['num'] = round($result['num'] / 10000, 1) . "<span style='font-size:12px;'>万</span>";
  27.             }
  28.         }
  29.         return $result['num'];
  30.     }
  31. }

  32. /*请求数据总和*/
  33. if(!function_exists('rc_getsum')){
  34.     function rc_getsum($table,$field,$con='',$format=''){
  35.         if($con){
  36.             $con =" WHERE ".$con;
  37.         }
  38.         $result = DB::fetch_first("SELECT SUM(".$field.") AS num FROM ".DB::table($table).$con);
  39.         if($format=='w'){
  40.             if($result['num']>=10000) {
  41.                 $result['num'] = round($result['num'] / 10000, 1) . "<span style='font-size:12px;'>万</span>";
  42.             }
  43.         }
  44.         return $result['num'];
  45.     }
  46. }

  47. /*动态修改数据*/
  48. if(!function_exists('rc_dataplus')) {
  49.     function rc_dataplus($table, $field, $con = '')
  50.     {
  51.         if ($con) {
  52.             $con = " WHERE " . $con;
  53.         }
  54.         DB::query("UPDATE " . DB::table($table) . " SET " . $field . " = " . $field . " - (-1) " . $con);
  55.     }
  56. }
  57. if(!function_exists('rc_dataminus')) {
  58.     function rc_dataminus($table, $field, $con = '')
  59.     {
  60.         if ($con) {
  61.             $con = " WHERE " . $con;
  62.         }
  63.         DB::query("UPDATE " . DB::table($table) . " SET " . $field . " = " . $field . " -1 " . $con);
  64.     }
  65. }
  66. if(!function_exists('rc_datachange')) {
  67.     function rc_datachange($table,$field,$change,$con=''){
  68.         if($con){
  69.             $con =" WHERE ".$con;
  70.         }
  71.         $cdr = -$change;
  72.         DB::query("UPDATE ".DB::table($table)." SET ".$field." = ".$field." -".$cdr." ".$con);
  73.     }
  74. }

  75. /*设置状态*/
  76. if(!function_exists('rc_status')) {
  77.     function rc_status($table, $con = '', $status = '0')
  78.     {
  79.         if ($con) {
  80.             $con = " WHERE " . $con;
  81.         }
  82.         $result = DB::query("UPDATE " . DB::table($table) . " SET status = '" . intval($status) . "' " . $con);
  83.     }
  84. }

  85. /*请求单个数据(组)*/
  86. if(!function_exists('rc_getarray')) {
  87.     function rc_getarray($table,$con='',$order=''){
  88.         if($con){
  89.             $con =" WHERE ".$con;
  90.         }
  91.         if($order){
  92.             $order =" ORDER BY ".$order;
  93.         }
  94.         $result = DB::fetch_first("SELECT * FROM ".DB::table($table).$con.$order);
  95.         return $result;
  96.     }
  97. }

  98. /*请求单个数据*/
  99. if(!function_exists('rc_get')) {
  100.     function rc_get($table,$field,$con='',$order=''){
  101.         if($con){
  102.             $con =" WHERE ".$con;
  103.         }
  104.         if($order){
  105.             $order =" ORDER BY ".$order;
  106.         }
  107.         $result = DB::fetch_first("SELECT ".$field." FROM ".DB::table($table).$con.$order);
  108.         return $result[$field];
  109.     }
  110. }

  111. /*插入数据*/
  112. if(!function_exists('rc_insert')) {
  113.     function rc_insert($table,$cs){
  114.         return DB::insert($table,$cs,true);
  115.     }
  116. }

  117. /*编辑数据*/
  118. if(!function_exists('rc_update')) {
  119.     function rc_update($table,$cs,$bs){
  120.         return DB::update($table,$cs,$bs);
  121.     }
  122. }

  123. /*删除数据*/
  124. if(!function_exists('rc_delete')) {
  125.     function rc_delete($table,$bs){
  126.         return DB::delete($table,$bs);
  127.     }
  128. }
复制代码

左耳聆听,创意时空。
服务客户,以及客户的客户。任何问题欢迎联系!
您需要登录后才可以回帖 登录 | 创建通行证

本版积分规则

快速回复 返回顶部 返回列表