Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
PHP-MySQLi-Database-Class
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
PHP-MySQLi-Database-Class
Commits
158eec4f
Commit
158eec4f
authored
Jun 01, 2017
by
Alexander Butenko
Committed by
GitHub
Jun 01, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #601 from thingNumber1/patch-1
Adding ORDER BY REGEXP possibilites
parents
72d231de
dd37055b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
9 deletions
+12
-9
MysqliDb.php
MysqliDb.php
+12
-9
No files found.
MysqliDb.php
View file @
158eec4f
...
...
@@ -1080,16 +1080,16 @@ class MysqliDb
/**
* This method allows you to specify multiple (method chaining optional) ORDER BY statements for SQL queries.
*
* @uses $MySqliDb->orderBy('id', 'desc')->orderBy('name', 'desc');
* @uses $MySqliDb->orderBy('id', 'desc')->orderBy('name', 'desc'
, '^[a-z]')->orderBy('name', 'desc'
);
*
* @param string $orderByField The name of the database field.
* @param string $orderByDirection Order direction.
* @param
array $customFields Fieldset for ORDER BY FIELD()
ordering
* @param
mixed $customFieldsOrRegExp Array with fieldset for ORDER BY FIELD() ordering or string with regular expresion for ORDER BY REGEXP
ordering
*
* @throws Exception
* @return MysqliDb
*/
public
function
orderBy
(
$orderByField
,
$orderbyDirection
=
"DESC"
,
$customFields
=
null
)
public
function
orderBy
(
$orderByField
,
$orderbyDirection
=
"DESC"
,
$customFields
OrRegExp
=
null
)
{
$allowedDirection
=
Array
(
"ASC"
,
"DESC"
);
$orderbyDirection
=
strtoupper
(
trim
(
$orderbyDirection
));
...
...
@@ -1105,12 +1105,15 @@ class MysqliDb
throw
new
Exception
(
'Wrong order direction: '
.
$orderbyDirection
);
}
if
(
is_array
(
$customFields
))
{
foreach
(
$customFields
as
$key
=>
$value
)
{
$customFields
[
$key
]
=
preg_replace
(
"/[^-a-z0-9\.\(\),_` ]+/i"
,
''
,
$value
);
if
(
is_array
(
$customFields
OrRegExp
))
{
foreach
(
$customFields
OrRegExp
as
$key
=>
$value
)
{
$customFields
OrRegExp
[
$key
]
=
preg_replace
(
"/[^-a-z0-9\.\(\),_` ]+/i"
,
''
,
$value
);
}
$orderByField
=
'FIELD ('
.
$orderByField
.
', "'
.
implode
(
'","'
,
$customFields
)
.
'")'
;
$orderByField
=
'FIELD ('
.
$orderByField
.
', "'
.
implode
(
'","'
,
$customFieldsOrRegExp
)
.
'")'
;
}
elseif
(
is_string
(
$customFieldsOrRegExp
)){
$orderByField
=
$orderByField
.
" REGEXP '"
.
$customFieldsOrRegExp
.
"'"
;
}
elseif
(
$customFieldsOrRegExp
!==
null
){
throw
new
Exception
(
'Wrong custom field or Regular Expression: '
.
$customFieldsOrRegExp
);
}
$this
->
_orderBy
[
$orderByField
]
=
$orderbyDirection
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment