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
3d1d38e7
Commit
3d1d38e7
authored
Jun 28, 2014
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
same
parent
0815d1de
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
24 deletions
+25
-24
readme.md
readme.md
+25
-24
No files found.
readme.md
View file @
3d1d38e7
...
@@ -65,9 +65,9 @@ $data = Array(
...
@@ -65,9 +65,9 @@ $data = Array(
// Supported intervals [s]econd, [m]inute, [h]hour, [d]day, [M]onth, [Y]ear
// Supported intervals [s]econd, [m]inute, [h]hour, [d]day, [M]onth, [Y]ear
);
);
$id
=
$db
->
insert
(
'users'
,
$data
);
$id
=
$db
->
insert
(
'users'
,
$data
);
if
(
$id
)
if
(
$id
)
echo
'user was created. Id='
.
$id
;
echo
'user was created. Id='
.
$id
;
```
```
### Update Query
### Update Query
...
@@ -80,8 +80,8 @@ $data = Array (
...
@@ -80,8 +80,8 @@ $data = Array (
'active'
=>
$db
->
not
()
'active'
=>
$db
->
not
()
// active = !active;
// active = !active;
);
);
$db
->
where
(
'id'
,
1
);
$db
->
where
(
'id'
,
1
);
if
(
$db
->
update
(
'users'
,
$data
))
echo
'successfully updated'
;
if
(
$db
->
update
(
'users'
,
$data
))
echo
'successfully updated'
;
```
```
### Select Query
### Select Query
...
@@ -95,10 +95,7 @@ $users = $db->get('users', 10); //contains an Array 10 users
...
@@ -95,10 +95,7 @@ $users = $db->get('users', 10); //contains an Array 10 users
or select with custom columns set. Functions also could be used
or select with custom columns set. Functions also could be used
```
php
```
php
$stats
=
$db
->
getOne
(
"users"
,
"sum(id), count(*) as cnt"
);
$cols
=
Array
(
"id"
,
"name"
,
"email"
);
echo
"total "
.
$stats
[
'cnt'
]
.
"users found"
;
$cols
=
Array
(
"id, name, email"
);
$users
=
$db
->
get
(
"users"
,
null
,
$cols
);
$users
=
$db
->
get
(
"users"
,
null
,
$cols
);
if
(
$db
->
count
>
0
)
if
(
$db
->
count
>
0
)
foreach
(
$users
as
$user
)
{
foreach
(
$users
as
$user
)
{
...
@@ -112,6 +109,9 @@ or select just one row
...
@@ -112,6 +109,9 @@ or select just one row
$db
->
where
(
"id"
,
1
);
$db
->
where
(
"id"
,
1
);
$user
=
$db
->
getOne
(
"users"
);
$user
=
$db
->
getOne
(
"users"
);
echo
$user
[
'id'
];
echo
$user
[
'id'
];
$stats
=
$db
->
getOne
(
"users"
,
"sum(id), count(*) as cnt"
);
echo
"total "
.
$stats
[
'cnt'
]
.
"users found"
;
```
```
### Delete Query
### Delete Query
...
@@ -147,34 +147,33 @@ WARNING: In order to use column to column comparisons only raw where conditions
...
@@ -147,34 +147,33 @@ WARNING: In order to use column to column comparisons only raw where conditions
Regular == operator with variables:
Regular == operator with variables:
```
php
```
php
$db
->
where
(
'id'
,
1
);
$db
->
where
(
'id'
,
1
);
$db
->
where
(
'login'
,
'admin'
);
$db
->
where
(
'login'
,
'admin'
);
$results
=
$db
->
get
(
'users'
);
$results
=
$db
->
get
(
'users'
);
// Gives: SELECT * FROM users WHERE id=1 AND login='admin';
// Gives: SELECT * FROM users WHERE id=1 AND login='admin';
```
```
Regular == operator with column to column comparison:
Regular == operator with column to column comparison:
```
php
```
php
// WRONG
// WRONG
$db
->
where
(
'lastLogin'
,
'createdAt'
);
$db
->
where
(
'lastLogin'
,
'createdAt'
);
// CORRECT
// CORRECT
$db
->
where
(
'lastLogin = createdAt'
);
$db
->
where
(
'lastLogin = createdAt'
);
$results
=
$db
->
get
(
'users'
);
$results
=
$db
->
get
(
'users'
);
// Gives: SELECT * FROM users WHERE lastLogin = createdAt;
// Gives: SELECT * FROM users WHERE lastLogin = createdAt;
```
```
```
php
```
php
$db
->
where
(
'id'
,
50
,
">="
);
$db
->
where
(
'id'
,
50
,
">="
);
// or $db->where('id', Array('>=' => 50));
// or $db->where ('id', Array ('>=' => 50));
$results
=
$db
->
get
(
'users'
);
$results
=
$db
->
get
(
'users'
);
// Gives: SELECT * FROM users WHERE id >= 50;
// Gives: SELECT * FROM users WHERE id >= 50;
```
```
BETWEEN / NOT BETWEEN:
BETWEEN / NOT BETWEEN:
```
php
```
php
$db
->
where
(
'id'
,
Array
(
4
,
20
),
'between
'
);
$db
->
where
(
'id'
,
Array
(
4
,
20
),
'BETWEEN
'
);
// or $db->where
('id', Array('between' => Array(4, 20) )
);
// or $db->where
('id', Array ('BETWEEN' => Array(4, 20))
);
$results
=
$db
->
get
(
'users'
);
$results
=
$db
->
get
(
'users'
);
// Gives: SELECT * FROM users WHERE id BETWEEN 4 AND 20
// Gives: SELECT * FROM users WHERE id BETWEEN 4 AND 20
...
@@ -183,7 +182,7 @@ $results = $db->get('users');
...
@@ -183,7 +182,7 @@ $results = $db->get('users');
IN / NOT IN:
IN / NOT IN:
```
php
```
php
$db
->
where
(
'id'
,
Array
(
1
,
5
,
27
,
-
1
,
'd'
),
'IN'
);
$db
->
where
(
'id'
,
Array
(
1
,
5
,
27
,
-
1
,
'd'
),
'IN'
);
// or $db->where('id', Array( '
in
' => Array(1, 5, 27, -1, 'd') ) );
// or $db->where('id', Array( '
IN
' => Array(1, 5, 27, -1, 'd') ) );
$results
=
$db
->
get
(
'users'
);
$results
=
$db
->
get
(
'users'
);
// Gives: SELECT * FROM users WHERE id IN (1, 5, 27, -1, 'd');
// Gives: SELECT * FROM users WHERE id IN (1, 5, 27, -1, 'd');
...
@@ -207,14 +206,16 @@ $results = $db->get("users");
...
@@ -207,14 +206,16 @@ $results = $db->get("users");
Also you can use raw where conditions:
Also you can use raw where conditions:
```
php
```
php
$db
->
where
(
"id != companyId"
);
$db
->
where
(
"id != companyId"
);
$db
->
where
(
"DATE(createdAt) = DATE(lastLogin)"
);
$results
=
$db
->
get
(
"users"
);
$results
=
$db
->
get
(
"users"
);
```
```
Or raw condition with variables:
Or raw condition with variables:
```
php
```
php
$db
->
where
(
"id = ? or id = ?"
,
Array
(
6
,
2
));
$db
->
where
(
"(id = ? or id = ?)"
,
Array
(
6
,
2
));
$db
->
where
(
"login"
,
"mike"
)
$res
=
$db
->
get
(
"users"
);
$res
=
$db
->
get
(
"users"
);
// Gives: SELECT * FROM users W
ERE id = 2 or id = 2
;
// Gives: SELECT * FROM users W
HERE (id = 2 or id = 2) and login='mike'
;
```
```
...
...
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