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
ab6caff5
Commit
ab6caff5
authored
May 28, 2014
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added nicer where API to define operators
parent
c1d40ca6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
16 deletions
+22
-16
MysqliDb.php
MysqliDb.php
+8
-2
readme.md
readme.md
+10
-10
tests.php
tests.php
+4
-4
No files found.
MysqliDb.php
View file @
ab6caff5
...
...
@@ -357,8 +357,11 @@ class MysqliDb
*
* @return MysqliDb
*/
public
function
where
(
$whereProp
,
$whereValue
=
null
)
public
function
where
(
$whereProp
,
$whereValue
=
null
,
$operator
=
null
)
{
if
(
$operator
)
$whereValue
=
Array
(
$operator
=>
$whereValue
);
$this
->
_where
[
$whereProp
]
=
Array
(
"AND"
,
$whereValue
);
return
$this
;
}
...
...
@@ -373,8 +376,11 @@ class MysqliDb
*
* @return MysqliDb
*/
public
function
orWhere
(
$whereProp
,
$whereValue
=
null
)
public
function
orWhere
(
$whereProp
,
$whereValue
=
null
,
$operator
=
null
)
{
if
(
$operator
)
$whereValue
=
Array
(
$operator
=>
$whereValue
);
$this
->
_where
[
$whereProp
]
=
Array
(
"OR"
,
$whereValue
);
return
$this
;
}
...
...
readme.md
View file @
ab6caff5
...
...
@@ -133,23 +133,23 @@ $results = $db->get('users');
```
```
php
$db
->
where
(
'id'
,
Array
(
'>='
=>
50
)
);
$db
->
where
(
'id'
,
50
,
">="
);
$results
=
$db
->
get
(
'users'
);
// Gives: SELECT * FROM users WHERE id >= 50;
```
BETWEEN:
```
php
$db
->
where
(
'id'
,
Array
(
'between'
=>
Array
(
4
,
20
)
)
);
//$db->where('id', Array(
'not between' => Array(4, 20) )
);
$db
->
where
(
'id'
,
Array
(
4
,
20
),
'between'
);
//$db->where('id', Array(
4, 20), 'not between'
);
$results
=
$db
->
get
(
'users'
);
// Gives: SELECT * FROM users WHERE id BETWEEN 4 AND 20
```
IN:
```
php
$db
->
where
(
'id'
,
Array
(
'in'
=>
Array
(
1
,
5
,
27
,
-
1
,
'd'
)
)
);
//$db->where('id', Array(
'not in' => Array(1, 5, 27, -1, 'd') )
);
$db
->
where
(
'id'
,
Array
(
1
,
5
,
27
,
-
1
,
'd'
),
'IN'
);
//$db->where('id', Array(
1, 5, 27, -1, 'd'), 'NOT IN'
);
$results
=
$db
->
get
(
'users'
);
// Gives: SELECT * FROM users WHERE id IN (1, 5, 27, -1, 'd');
```
...
...
@@ -164,7 +164,7 @@ $results = $db->get('users');
NULL comparison:
```
php
$db
->
where
(
"lastName"
,
Array
(
"<=>"
=>
NULL
)
);
$db
->
where
(
"lastName"
,
NULL
,
'<=>'
);
$results
=
$db
->
get
(
"users"
);
// Gives: SELECT * FROM users where lastName <=> NULL
```
...
...
@@ -218,10 +218,10 @@ print_r ($products);
### Subqueries
```
php
$db
->
where
(
"id"
,
Array
(
"in"
=>
$db
->
subQuery
()
->
where
(
"qty"
,
Array
(
">"
=>
2
));
->
get
(
"products"
,
null
,
"userId"
)
)
);
$db
->
where
(
"id"
,
$db
->
subQuery
()
->
where
(
"qty"
,
2
,
">"
)
->
get
(
"products"
,
null
,
"userId"
)
,
'in'
);
$res
=
$db
->
get
(
"users"
);
// Gives SELECT * FROM users WHERE id IN (SELECT userId FROM products WHERE qty > 2)
...
...
tests.php
View file @
ab6caff5
...
...
@@ -138,7 +138,7 @@ if ($db->count != 3) {
//$users = $db->get("users");
//print_r ($users);
$db
->
where
(
"firstname"
,
Array
(
"LIKE"
=>
'%John%'
)
);
$db
->
where
(
"firstname"
,
'%John%'
,
'LIKE'
);
$users
=
$db
->
get
(
"users"
);
if
(
$db
->
count
!=
1
)
{
echo
"Invalid insert count in LIKE: "
.
$db
->
count
;
...
...
@@ -172,14 +172,14 @@ if ($r['password'] != '546f98b24edfdc3b9bbe0d241bd8b29783f71b32') {
exit
;
}
$db
->
where
(
"id"
,
Array
(
'
in'
=>
Array
(
'1'
,
'2'
,
'3'
))
);
$db
->
where
(
"id"
,
Array
(
'
1'
,
'2'
,
'3'
),
'IN'
);
$db
->
get
(
"users"
);
if
(
$db
->
count
!=
3
)
{
echo
"Invalid users count on where() with in "
;
exit
;
}
$db
->
where
(
"id"
,
Array
(
'
between'
=>
Array
(
'2'
,
'3'
))
);
$db
->
where
(
"id"
,
Array
(
'
2'
,
'3'
),
'between'
);
$db
->
get
(
"users"
);
if
(
$db
->
count
!=
2
)
{
echo
"Invalid users count on where() with between"
;
...
...
@@ -194,7 +194,7 @@ if ($db->count != 2) {
exit
;
}
$db
->
where
(
"lastName"
,
Array
(
"<=>"
=>
NULL
)
);
$db
->
where
(
"lastName"
,
NULL
,
'<=>'
);
$r
=
$db
->
get
(
"users"
);
if
(
$db
->
count
!=
1
)
{
echo
"Invalid users count on null where()"
;
...
...
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