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
6261af4f
Commit
6261af4f
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
b6d5e9bf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
12 deletions
+18
-12
MysqliDb.php
MysqliDb.php
+8
-2
readme.md
readme.md
+6
-6
tests.php
tests.php
+4
-4
No files found.
MysqliDb.php
View file @
6261af4f
...
...
@@ -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 @
6261af4f
...
...
@@ -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
```
...
...
tests.php
View file @
6261af4f
...
...
@@ -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