我正在尝试将一些 PHP 代码转换为 MySQL 存储过程。这是PHP代码:
$aORs = array(); // create an empty array to hold the individual criteria to be OR'd...
$months = explode('|',$_REQUEST['sSearch_'.$i]);
$sWhere .= '(';
foreach($months as $month) {
$year = intval(substr($month, 0, 4));
$mon = intval(substr($month, 5, 2));
array_push($aORs, '(MONTH(e.StartDate) = '.$mon.' and YEAR(e.StartDate) = '.$year.')');
}
$sWhere .= implode(" OR ",$aORs); // transform the array of criteria into a properly delimited WHERE clause...
$sWhere .= ')';
我将像这样将参数传递给存储过程:
2012-07|2012-10|2013-02
我无法弄清楚如何将上述输入解析为 WHERE 子句,如下所示:
(MONTH(e.sDate) = 07 AND YEAR(e.sDate) = 2012) OR
(MONTH(e.sDate) = 10 AND YEAR(e.sDate) = 2012) OR
(MONTH(e.sDate) = 02 AND YEAR(e.sDate) = 2013) OR
我怎样才能在存储过程中做到这一点?我见过“臭名昭著”的 split_str 函数,但我不知道可能有多少值。