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
f07da2ac
Commit
f07da2ac
authored
Jun 07, 2015
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #236 from avbdr/master
buildWhere refactoring and versioning
parents
baf4d2a1
9aceb949
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
37 deletions
+26
-37
MysqliDb.php
MysqliDb.php
+25
-36
dbObject.php
dbObject.php
+1
-1
No files found.
MysqliDb.php
View file @
f07da2ac
...
...
@@ -9,7 +9,7 @@
* @author Alexander V. Butenko <a.butenka@gmail.com>
* @copyright Copyright (c) 2010
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
* @version 2.
0
* @version 2.
1
**/
class
MysqliDb
{
...
...
@@ -484,12 +484,16 @@ class MysqliDb
*
* @return MysqliDb
*/
public
function
where
(
$whereProp
,
$whereValue
=
null
,
$operator
=
null
)
public
function
where
(
$whereProp
,
$whereValue
=
'DBNULL'
,
$operator
=
'='
,
$cond
=
'AND'
)
{
if
(
$operator
)
$whereValue
=
Array
(
$operator
=>
$whereValue
);
$this
->
_where
[]
=
Array
(
"AND"
,
$whereValue
,
$whereProp
);
// forkaround for an old operation api
if
(
is_array
(
$whereValue
)
&&
(
$key
=
key
(
$whereValue
))
!=
"0"
)
{
$operator
=
$key
;
$whereValue
=
$whereValue
[
$key
];
}
if
(
count
(
$this
->
_where
)
==
0
)
$cond
=
''
;
$this
->
_where
[]
=
Array
(
$cond
,
$whereProp
,
$operator
,
$whereValue
);
return
$this
;
}
...
...
@@ -503,13 +507,9 @@ class MysqliDb
*
* @return MysqliDb
*/
public
function
orWhere
(
$whereProp
,
$whereValue
=
null
,
$operator
=
null
)
public
function
orWhere
(
$whereProp
,
$whereValue
=
'DBNULL'
,
$operator
=
'='
)
{
if
(
$operator
)
$whereValue
=
Array
(
$operator
=>
$whereValue
);
$this
->
_where
[]
=
Array
(
"OR"
,
$whereValue
,
$whereProp
);
return
$this
;
return
$this
->
where
(
$whereProp
,
$whereValue
,
$operator
,
'OR'
);
}
/**
* This method allows you to concatenate joins for the final SQL statement.
...
...
@@ -870,33 +870,17 @@ class MysqliDb
if
(
empty
(
$this
->
_where
))
return
;
//Prepa
ir
the where portion of the query
//Prepa
re
the where portion of the query
$this
->
_query
.=
' WHERE'
;
// Remove first AND/OR concatenator
$this
->
_where
[
0
][
0
]
=
''
;
foreach
(
$this
->
_where
as
$cond
)
{
list
(
$concat
,
$wValue
,
$wKey
)
=
$cond
;
list
(
$concat
,
$varName
,
$operator
,
$val
)
=
$cond
;
$this
->
_query
.=
" "
.
$concat
.
" "
.
$varName
;
$this
->
_query
.=
" "
.
$concat
.
" "
.
$wKey
;
// Empty value (raw where condition in wKey)
if
(
$wValue
===
null
)
continue
;
// Simple = comparison
if
(
!
is_array
(
$wValue
))
$wValue
=
Array
(
'='
=>
$wValue
);
$key
=
key
(
$wValue
);
$val
=
$wValue
[
$key
];
switch
(
strtolower
(
$key
))
{
case
'0'
:
$this
->
_bindParams
(
$wValue
);
break
;
switch
(
strtolower
(
$operator
))
{
case
'not in'
:
case
'in'
:
$comparison
=
' '
.
$
key
.
' ('
;
$comparison
=
' '
.
$
operator
.
' ('
;
if
(
is_object
(
$val
))
{
$comparison
.=
$this
->
_buildPair
(
""
,
$val
);
}
else
{
...
...
@@ -909,15 +893,20 @@ class MysqliDb
break
;
case
'not between'
:
case
'between'
:
$this
->
_query
.=
"
$
key
? AND ? "
;
$this
->
_query
.=
"
$
operator
? AND ? "
;
$this
->
_bindParams
(
$val
);
break
;
case
'not exists'
:
case
'exists'
:
$this
->
_query
.=
$
key
.
$this
->
_buildPair
(
""
,
$val
);
$this
->
_query
.=
$
operator
.
$this
->
_buildPair
(
""
,
$val
);
break
;
default
:
$this
->
_query
.=
$this
->
_buildPair
(
$key
,
$val
);
if
(
is_array
(
$val
))
$this
->
_bindParams
(
$val
);
else
if
(
$val
===
null
)
$this
->
_query
.=
$operator
.
" NULL"
;
else
if
(
$val
!=
'DBNULL'
)
$this
->
_query
.=
$this
->
_buildPair
(
$operator
,
$val
);
}
}
}
...
...
dbObject.php
View file @
f07da2ac
...
...
@@ -7,7 +7,7 @@
* @author Alexander V. Butenko <a.butenka@gmail.com>
* @copyright Copyright (c) 2015
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
* @version 2.
0
* @version 2.
1
*
* @method int count ()
* @method mixed byId (string $id, mixed $fields)
...
...
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