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
30a07506
Commit
30a07506
authored
May 02, 2014
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added test for join
parent
a5f25d09
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
32 deletions
+73
-32
tests.php
tests.php
+73
-32
No files found.
tests.php
View file @
30a07506
...
...
@@ -15,37 +15,66 @@ $tables = Array (
'createdAt'
=>
'datetime'
,
'expires'
=>
'datetime'
,
'loginCount'
=>
'int(10) default 0'
),
'products'
=>
Array
(
'customerId'
=>
'int(10) not null'
,
'userId'
=>
'int(10) not null'
,
'productName'
=>
'char(50)'
)
);
$data
=
Array
(
Array
(
'login'
=>
'user1'
,
'customerId'
=>
10
,
'firstName'
=>
'John'
,
'lastName'
=>
'Doe'
,
'password'
=>
$db
->
func
(
'SHA1(?)'
,
Array
(
"secretpassword+salt"
)),
'createdAt'
=>
$db
->
now
(),
'expires'
=>
$db
->
now
(
'+1Y'
),
'loginCount'
=>
$db
->
inc
()
),
Array
(
'login'
=>
'user2'
,
'customerId'
=>
10
,
'firstName'
=>
'Mike'
,
'lastName'
=>
NULL
,
'password'
=>
$db
->
func
(
'SHA1(?)'
,
Array
(
"secretpassword2+salt"
)),
'createdAt'
=>
$db
->
now
(),
'expires'
=>
$db
->
now
(
'+1Y'
),
'loginCount'
=>
$db
->
inc
(
2
)
'users'
=>
Array
(
Array
(
'login'
=>
'user1'
,
'customerId'
=>
10
,
'firstName'
=>
'John'
,
'lastName'
=>
'Doe'
,
'password'
=>
$db
->
func
(
'SHA1(?)'
,
Array
(
"secretpassword+salt"
)),
'createdAt'
=>
$db
->
now
(),
'expires'
=>
$db
->
now
(
'+1Y'
),
'loginCount'
=>
$db
->
inc
()
),
Array
(
'login'
=>
'user2'
,
'customerId'
=>
10
,
'firstName'
=>
'Mike'
,
'lastName'
=>
NULL
,
'password'
=>
$db
->
func
(
'SHA1(?)'
,
Array
(
"secretpassword2+salt"
)),
'createdAt'
=>
$db
->
now
(),
'expires'
=>
$db
->
now
(
'+1Y'
),
'loginCount'
=>
$db
->
inc
(
2
)
),
Array
(
'login'
=>
'user3'
,
'customerId'
=>
11
,
'firstName'
=>
'Pete'
,
'lastName'
=>
'D'
,
'password'
=>
$db
->
func
(
'SHA1(?)'
,
Array
(
"secretpassword2+salt"
)),
'createdAt'
=>
$db
->
now
(),
'expires'
=>
$db
->
now
(
'+1Y'
),
'loginCount'
=>
$db
->
inc
(
3
)
)
),
Array
(
'login'
=>
'user3'
,
'customerId'
=>
11
,
'firstName'
=>
'Pete'
,
'lastName'
=>
'D'
,
'password'
=>
$db
->
func
(
'SHA1(?)'
,
Array
(
"secretpassword2+salt"
)),
'createdAt'
=>
$db
->
now
(),
'expires'
=>
$db
->
now
(
'+1Y'
),
'loginCount'
=>
$db
->
inc
(
3
)
)
'products'
=>
Array
(
Array
(
'customerId'
=>
1
,
'userId'
=>
1
,
'productName'
=>
'product1'
,
),
Array
(
'customerId'
=>
1
,
'userId'
=>
1
,
'productName'
=>
'product2'
,
),
Array
(
'customerId'
=>
1
,
'userId'
=>
1
,
'productName'
=>
'product3'
,
),
Array
(
'customerId'
=>
1
,
'userId'
=>
2
,
'productName'
=>
'product4'
,
),
Array
(
'customerId'
=>
1
,
'userId'
=>
2
,
'productName'
=>
'product5'
,
),
)
);
function
createTable
(
$name
,
$data
)
{
...
...
@@ -64,12 +93,15 @@ foreach ($tables as $name => $fields) {
createTable
(
$name
,
$fields
);
}
foreach
(
$data
as
$d
)
{
$id
=
$db
->
insert
(
"users"
,
$d
);
if
(
$id
)
$d
[
'id'
]
=
$id
;
else
{
echo
"failed to insert: "
.
$db
->
getLastQuery
()
.
"
\n
"
.
$db
->
getLastError
();
foreach
(
$data
as
$name
=>
$datas
)
{
foreach
(
$datas
as
$d
)
{
$id
=
$db
->
insert
(
$name
,
$d
);
if
(
$id
)
$d
[
'id'
]
=
$id
;
else
{
echo
"failed to insert: "
.
$db
->
getLastQuery
()
.
"
\n
"
.
$db
->
getLastError
();
}
}
}
...
...
@@ -147,12 +179,21 @@ if ($db->count != 1) {
exit
;
}
$db
->
join
(
"users u"
,
"p.userId=u.id"
,
"LEFT"
);
$db
->
where
(
"u.login"
,
'user2'
);
$products
=
$db
->
get
(
"products p"
,
null
,
"u.login, p.productName"
);
if
(
$db
->
count
!=
2
)
{
echo
"Invalid products count on join ()"
;
exit
;
}
$db
->
delete
(
"users"
);
$db
->
get
(
"users"
);
if
(
$db
->
count
!=
0
)
{
echo
"Invalid users count after delete"
;
exit
;
}
$db
->
delete
(
"products"
);
echo
"All done"
;
//print_r($db->rawQuery("CALL simpleproc(?)",Array("test")));
...
...
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