當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataFilter::toSQLStr方法代碼示例

本文整理匯總了PHP中DataFilter::toSQLStr方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataFilter::toSQLStr方法的具體用法?PHP DataFilter::toSQLStr怎麽用?PHP DataFilter::toSQLStr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DataFilter的用法示例。


在下文中一共展示了DataFilter::toSQLStr方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: buildSingleParam

 protected static function buildSingleParam($paramName, $column, $filter)
 {
     $sql = "";
     $param = "";
     $pcolumn = preg_replace('/[^\\da-z]/i', '_', $column);
     $driver = Setting::get('db.driver');
     $column = ActiveRecord::formatSingleCriteria($column, $driver);
     ## quote field if it is containing illegal char
     if (!preg_match("/^[a-zA-Z_][a-zA-Z0-9_]*\$/", str_replace(".", "", $column))) {
         $column = "{$column}";
     }
     switch ($filter['type']) {
         case "string":
             if ($filter['value'] != "" || $filter['operator'] == 'Is Empty') {
                 $sCol = DataFilter::toSQLStr("{$column}", $driver);
                 $spCol = DataFilter::toSQLStr(":{$paramName}_{$pcolumn}", $driver);
                 switch ($filter['operator']) {
                     case "Contains":
                         $sql = "{$sCol} LIKE {$spCol}";
                         $param = "%{$filter['value']}%";
                         break;
                     case "Does Not Contain":
                         $sql = "{$sCol} NOT LIKE {$spCol}";
                         $param = "%{$filter['value']}%";
                         break;
                     case "Is Equal To":
                         $sql = "{$sCol} LIKE {$spCol}";
                         $param = "{$filter['value']}";
                         break;
                     case "Starts With":
                         $sql = "{$sCol} LIKE {$spCol}";
                         $param = "{$filter['value']}%";
                         break;
                     case "Ends With":
                         $sql = "{$sCol} LIKE {$spCol}";
                         $param = "%{$filter['value']}";
                         break;
                     case "Is Any Of":
                         $param_raw = preg_split('/\\s+/', trim($filter['value']));
                         $param = [];
                         $psql = [];
                         foreach ($param_raw as $k => $p) {
                             $param[":{$paramName}_{$pcolumn}_{$k}"] = "%{$p}%";
                             $spCol = DataFilter::toSQLStr(":{$paramName}_{$pcolumn}_{$k}", $driver);
                             $psql[] = "{$sCol} LIKE {$spCol}";
                         }
                         $sql = "(" . implode(" OR ", $psql) . ")";
                         break;
                     case "Is Not Any Of":
                         $param_raw = preg_split('/\\s+/', trim($filter['value']));
                         $param = [];
                         $psql = [];
                         foreach ($param_raw as $k => $p) {
                             $param[":{$paramName}_{$pcolumn}_{$k}"] = "%{$p}%";
                             $spCol = DataFilter::toSQLStr(":{$paramName}_{$pcolumn}_{$k}", $driver);
                             $psql[] = "{$sCol} LIKE {$spCol}";
                         }
                         $sql = "(" . implode(" AND ", $psql) . ")";
                         break;
                     case "Is Empty":
                         $sql = "({$column} LIKE '' OR {$column} IS NULL)";
                         break;
                 }
             }
             break;
         case "number":
             if ($filter['value'] != "" || $filter['operator'] == 'Is Empty') {
                 switch ($filter['operator']) {
                     case "=":
                     case "<>":
                     case ">":
                     case '>':
                     case '>=':
                     case '<=':
                     case '<':
                         $sql = "{$column} {$filter['operator']} :{$paramName}_{$pcolumn}";
                         $param = "{$filter['value']}";
                         break;
                     case "Is Empty":
                         $sql = "({$column} IS NULL)";
                         break;
                 }
             }
             break;
         case "date":
             switch ($filter['operator']) {
                 case "Between":
                 case "Weekly":
                 case "Monthly":
                 case "Yearly":
                     if (@$filter['value']['from'] != '' && @$filter['value']['to'] != '') {
                         $a = self::toSQLDateTime(":{$paramName}_{$pcolumn}_from", $driver);
                         $b = self::toSQLDateTime(":{$paramName}_{$pcolumn}_to", $driver);
                         $sql = "({$column} BETWEEN {$a} AND {$b})";
                         $fromStartHour = date('Y-m-d 23:59:00', strtotime('-1 day', strtotime(@$filter['value']['from'])));
                         $toLastHour = date('Y-m-d 23:59:00', strtotime(@$filter['value']['to']));
                         $param = [":{$paramName}_{$pcolumn}_from" => $fromStartHour, ":{$paramName}_{$pcolumn}_to" => $toLastHour];
                     }
                     break;
                 case "Not Between":
//.........這裏部分代碼省略.........
開發者ID:rizabudi,項目名稱:plansys,代碼行數:101,代碼來源:DataFilter.php


注:本文中的DataFilter::toSQLStr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。