limit_offset() function refinement

This commit is contained in:
Nate 2019-07-01 20:52:54 -06:00
parent 492d03a5b9
commit fad7c24b90
1 changed files with 3 additions and 4 deletions

View File

@ -2133,15 +2133,14 @@ function number_pad($number,$n) {
//validate and format limit and offset clause of select statement //validate and format limit and offset clause of select statement
if (!function_exists('limit_offset')) { if (!function_exists('limit_offset')) {
function limit_offset($limit, $offset) { function limit_offset($limit, $offset = 0) {
$regex = '#[^0-9]#'; $regex = '#[^0-9]#';
$limit = preg_replace($regex, '', $limit); $limit = preg_replace($regex, '', $limit);
$offset = preg_replace($regex, '', $offset); $offset = preg_replace($regex, '', $offset);
if (is_numeric($limit) && $limit > 0) { if (is_numeric($limit) && $limit > 0) {
$clause .= ' limit '.$limit; $clause .= ' limit '.$limit;
if (is_numeric($offset)) { $offset = is_numeric($offset) ? $offset : 0;
$clause .= ' offset '.$offset; $clause .= ' offset '.$offset;
}
} }
return $clause.' '; return $clause.' ';
} }