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 (
...
@@ -15,37 +15,66 @@ $tables = Array (
'createdAt'
=>
'datetime'
,
'createdAt'
=>
'datetime'
,
'expires'
=>
'datetime'
,
'expires'
=>
'datetime'
,
'loginCount'
=>
'int(10) default 0'
'loginCount'
=>
'int(10) default 0'
),
'products'
=>
Array
(
'customerId'
=>
'int(10) not null'
,
'userId'
=>
'int(10) not null'
,
'productName'
=>
'char(50)'
)
)
);
);
$data
=
Array
(
$data
=
Array
(
Array
(
'login'
=>
'user1'
,
'users'
=>
Array
(
'customerId'
=>
10
,
Array
(
'login'
=>
'user1'
,
'firstName'
=>
'John'
,
'customerId'
=>
10
,
'lastName'
=>
'Doe'
,
'firstName'
=>
'John'
,
'password'
=>
$db
->
func
(
'SHA1(?)'
,
Array
(
"secretpassword+salt"
)),
'lastName'
=>
'Doe'
,
'createdAt'
=>
$db
->
now
(),
'password'
=>
$db
->
func
(
'SHA1(?)'
,
Array
(
"secretpassword+salt"
)),
'expires'
=>
$db
->
now
(
'+1Y'
),
'createdAt'
=>
$db
->
now
(),
'loginCount'
=>
$db
->
inc
()
'expires'
=>
$db
->
now
(
'+1Y'
),
),
'loginCount'
=>
$db
->
inc
()
Array
(
'login'
=>
'user2'
,
),
'customerId'
=>
10
,
Array
(
'login'
=>
'user2'
,
'firstName'
=>
'Mike'
,
'customerId'
=>
10
,
'lastName'
=>
NULL
,
'firstName'
=>
'Mike'
,
'password'
=>
$db
->
func
(
'SHA1(?)'
,
Array
(
"secretpassword2+salt"
)),
'lastName'
=>
NULL
,
'createdAt'
=>
$db
->
now
(),
'password'
=>
$db
->
func
(
'SHA1(?)'
,
Array
(
"secretpassword2+salt"
)),
'expires'
=>
$db
->
now
(
'+1Y'
),
'createdAt'
=>
$db
->
now
(),
'loginCount'
=>
$db
->
inc
(
2
)
'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'
,
'products'
=>
Array
(
'customerId'
=>
11
,
Array
(
'customerId'
=>
1
,
'firstName'
=>
'Pete'
,
'userId'
=>
1
,
'lastName'
=>
'D'
,
'productName'
=>
'product1'
,
'password'
=>
$db
->
func
(
'SHA1(?)'
,
Array
(
"secretpassword2+salt"
)),
),
'createdAt'
=>
$db
->
now
(),
Array
(
'customerId'
=>
1
,
'expires'
=>
$db
->
now
(
'+1Y'
),
'userId'
=>
1
,
'loginCount'
=>
$db
->
inc
(
3
)
'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
)
{
function
createTable
(
$name
,
$data
)
{
...
@@ -64,12 +93,15 @@ foreach ($tables as $name => $fields) {
...
@@ -64,12 +93,15 @@ foreach ($tables as $name => $fields) {
createTable
(
$name
,
$fields
);
createTable
(
$name
,
$fields
);
}
}
foreach
(
$data
as
$d
)
{
$id
=
$db
->
insert
(
"users"
,
$d
);
foreach
(
$data
as
$name
=>
$datas
)
{
if
(
$id
)
foreach
(
$datas
as
$d
)
{
$d
[
'id'
]
=
$id
;
$id
=
$db
->
insert
(
$name
,
$d
);
else
{
if
(
$id
)
echo
"failed to insert: "
.
$db
->
getLastQuery
()
.
"
\n
"
.
$db
->
getLastError
();
$d
[
'id'
]
=
$id
;
else
{
echo
"failed to insert: "
.
$db
->
getLastQuery
()
.
"
\n
"
.
$db
->
getLastError
();
}
}
}
}
}
...
@@ -147,12 +179,21 @@ if ($db->count != 1) {
...
@@ -147,12 +179,21 @@ if ($db->count != 1) {
exit
;
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
->
delete
(
"users"
);
$db
->
get
(
"users"
);
$db
->
get
(
"users"
);
if
(
$db
->
count
!=
0
)
{
if
(
$db
->
count
!=
0
)
{
echo
"Invalid users count after delete"
;
echo
"Invalid users count after delete"
;
exit
;
exit
;
}
}
$db
->
delete
(
"products"
);
echo
"All done"
;
echo
"All done"
;
//print_r($db->rawQuery("CALL simpleproc(?)",Array("test")));
//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