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
07078e0a
Commit
07078e0a
authored
Jun 22, 2015
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Partical fix for a dbObject usage with setPrefix()
parent
7ec9f667
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
10 deletions
+13
-10
dbObject.php
dbObject.php
+4
-3
dbObjectTests.php
tests/dbObjectTests.php
+9
-7
No files found.
dbObject.php
View file @
07078e0a
...
@@ -282,7 +282,7 @@ class dbObject {
...
@@ -282,7 +282,7 @@ class dbObject {
* @return dbObject|array
* @return dbObject|array
*/
*/
private
function
byId
(
$id
,
$fields
=
null
)
{
private
function
byId
(
$id
,
$fields
=
null
)
{
$this
->
db
->
where
(
$this
->
dbTable
.
'.'
.
$this
->
primaryKey
,
$id
);
$this
->
db
->
where
(
MysqliDb
::
$prefix
.
$this
->
dbTable
.
'.'
.
$this
->
primaryKey
,
$id
);
return
$this
->
getOne
(
$fields
);
return
$this
->
getOne
(
$fields
);
}
}
...
@@ -365,7 +365,8 @@ class dbObject {
...
@@ -365,7 +365,8 @@ class dbObject {
$joinObj
=
new
$objectName
;
$joinObj
=
new
$objectName
;
if
(
!
$key
)
if
(
!
$key
)
$key
=
$objectName
.
"id"
;
$key
=
$objectName
.
"id"
;
$joinStr
=
"
{
$this
->
dbTable
}
.
{
$key
}
=
{
$joinObj
->
dbTable
}
.
{
$joinObj
->
primaryKey
}
"
;
$joinStr
=
MysqliDb
::
$prefix
.
$this
->
dbTable
.
".
{
$key
}
= "
.
MysqliDb
::
$prefix
.
"
{
$joinObj
->
dbTable
}
.
{
$joinObj
->
primaryKey
}
"
;
$this
->
db
->
join
(
$joinObj
->
dbTable
,
$joinStr
,
$joinType
);
$this
->
db
->
join
(
$joinObj
->
dbTable
,
$joinStr
,
$joinType
);
return
$this
;
return
$this
;
}
}
...
@@ -601,7 +602,7 @@ class dbObject {
...
@@ -601,7 +602,7 @@ class dbObject {
*
*
* Calling autoload() without path will set path to dbObjectPath/models/ directory
* Calling autoload() without path will set path to dbObjectPath/models/ directory
*
*
* @param string $path
* @param string $path
*/
*/
public
static
function
autoload
(
$path
=
null
)
{
public
static
function
autoload
(
$path
=
null
)
{
if
(
$path
)
if
(
$path
)
...
...
tests/dbObjectTests.php
View file @
07078e0a
...
@@ -4,6 +4,8 @@ require_once ("../MysqliDb.php");
...
@@ -4,6 +4,8 @@ require_once ("../MysqliDb.php");
require_once
(
"../dbObject.php"
);
require_once
(
"../dbObject.php"
);
$db
=
new
Mysqlidb
(
'localhost'
,
'root'
,
''
,
'testdb'
);
$db
=
new
Mysqlidb
(
'localhost'
,
'root'
,
''
,
'testdb'
);
$prefix
=
't_'
;
$db
->
setPrefix
(
$prefix
);
dbObject
::
autoload
(
"models"
);
dbObject
::
autoload
(
"models"
);
$tables
=
Array
(
$tables
=
Array
(
...
@@ -91,8 +93,8 @@ function createTable ($name, $data) {
...
@@ -91,8 +93,8 @@ function createTable ($name, $data) {
// rawQuery test
// rawQuery test
foreach
(
$tables
as
$name
=>
$fields
)
{
foreach
(
$tables
as
$name
=>
$fields
)
{
$db
->
rawQuery
(
"DROP TABLE "
.
$name
);
$db
->
rawQuery
(
"DROP TABLE "
.
$
prefix
.
$
name
);
createTable
(
$name
,
$fields
);
createTable
(
$
prefix
.
$
name
,
$fields
);
}
}
foreach
(
$data
as
$name
=>
$datas
)
{
foreach
(
$data
as
$name
=>
$datas
)
{
...
@@ -134,7 +136,7 @@ if (!is_array ($products[0]['userId'])) {
...
@@ -134,7 +136,7 @@ if (!is_array ($products[0]['userId'])) {
exit
;
exit
;
}
}
$depts
=
product
::
join
(
'user'
)
->
orderBy
(
'products.id'
,
'desc'
)
->
get
(
5
);
$depts
=
product
::
join
(
'user'
)
->
orderBy
(
'
t_
products.id'
,
'desc'
)
->
get
(
5
);
foreach
(
$depts
as
$d
)
{
foreach
(
$depts
as
$d
)
{
if
(
!
is_object
(
$d
))
{
if
(
!
is_object
(
$d
))
{
echo
"Return should be an object
\n
"
;
echo
"Return should be an object
\n
"
;
...
@@ -244,10 +246,10 @@ if (!user::byId(1) instanceof user)
...
@@ -244,10 +246,10 @@ if (!user::byId(1) instanceof user)
if
(
!
is_array
(
user
::
ArrayBuilder
()
->
byId
(
1
)))
if
(
!
is_array
(
user
::
ArrayBuilder
()
->
byId
(
1
)))
echo
"wrong return type2"
;
echo
"wrong return type2"
;
if
(
!
is_array
(
product
::
join
(
'user'
)
->
orderBy
(
'products.id'
,
'desc'
)
->
get
(
2
)))
if
(
!
is_array
(
product
::
join
(
'user'
)
->
orderBy
(
'
t_
products.id'
,
'desc'
)
->
get
(
2
)))
echo
"wrong return type2"
;
echo
"wrong return type2"
;
if
(
!
is_array
(
product
::
orderBy
(
'products.id'
,
'desc'
)
->
join
(
'user'
)
->
get
(
2
)))
if
(
!
is_array
(
product
::
orderBy
(
'
t_
products.id'
,
'desc'
)
->
join
(
'user'
)
->
get
(
2
)))
echo
"wrong return type2"
;
echo
"wrong return type2"
;
$u
=
new
user
;
$u
=
new
user
;
...
@@ -255,10 +257,10 @@ if (!$u->byId(1) instanceof user)
...
@@ -255,10 +257,10 @@ if (!$u->byId(1) instanceof user)
echo
"wrong return type2"
;
echo
"wrong return type2"
;
$p
=
new
product
;
$p
=
new
product
;
if
(
!
is_array
(
$p
->
join
(
'user'
)
->
orderBy
(
'products.id'
,
'desc'
)
->
get
(
2
)))
if
(
!
is_array
(
$p
->
join
(
'user'
)
->
orderBy
(
'
t_
products.id'
,
'desc'
)
->
get
(
2
)))
echo
"wrong return type2"
;
echo
"wrong return type2"
;
if
(
!
is_array
(
$p
->
orderBy
(
'products.id'
,
'desc'
)
->
join
(
'user'
)
->
get
(
2
)))
if
(
!
is_array
(
$p
->
orderBy
(
'
t_
products.id'
,
'desc'
)
->
join
(
'user'
)
->
get
(
2
)))
echo
"wrong return type2"
;
echo
"wrong return type2"
;
echo
"All done"
;
echo
"All done"
;
...
...
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