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
d2aa5131
Commit
d2aa5131
authored
May 17, 2015
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API change
parent
73bd522a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
26 deletions
+35
-26
dbObject.php
dbObject.php
+23
-22
test.php
dbObject/test.php
+12
-4
No files found.
dbObject.php
View file @
d2aa5131
...
...
@@ -22,7 +22,7 @@ abstract class dbObject {
$modelName
=
$this
->
relations
[
$name
][
1
];
switch
(
$relationType
)
{
case
'hasone'
:
return
$modelName
::
byId
(
$this
->
data
[
$name
]);
return
$modelName
::
ObjectBuilder
()
->
byId
(
$this
->
data
[
$name
]);
break
;
case
'hasmany'
:
$key
=
$this
->
relations
[
$name
][
2
];
...
...
@@ -44,7 +44,7 @@ abstract class dbObject {
}
public
function
__isset
(
$name
)
{
if
(
$this
->
data
[
$name
]
)
if
(
isset
(
$this
->
data
[
$name
])
)
return
isset
(
$this
->
data
[
$name
]);
if
(
property_exists
(
$this
->
db
,
$name
))
...
...
@@ -108,22 +108,21 @@ abstract class dbObject {
}
p
ublic
static
function
byId
(
$id
,
$fields
=
null
)
{
return
static
::
getOne
(
$fields
,
$id
);
p
rivate
function
byId
(
$id
,
$fields
=
null
)
{
return
$this
->
getOne
(
$fields
,
$id
);
}
public
static
function
getOne
(
$fields
=
null
,
$primaryKey
=
null
,
$obj
=
null
)
{
$obj
=
new
static
;
private
function
getOne
(
$fields
=
null
,
$primaryKey
=
null
)
{
if
(
$primaryKey
)
$
obj
->
db
->
where
(
$obj
->
primaryKey
,
$primaryKey
);
$
this
->
db
->
where
(
$this
->
primaryKey
,
$primaryKey
);
$results
=
$
obj
->
db
->
getOne
(
$obj
->
dbTable
,
$fields
);
if
(
isset
(
$
obj
->
jsonFields
)
&&
is_array
(
$obj
->
jsonFields
))
{
foreach
(
$
obj
->
jsonFields
as
$key
)
$results
=
$
this
->
db
->
getOne
(
$this
->
dbTable
,
$fields
);
if
(
isset
(
$
this
->
jsonFields
)
&&
is_array
(
$this
->
jsonFields
))
{
foreach
(
$
this
->
jsonFields
as
$key
)
$results
[
$key
]
=
json_decode
(
$results
[
$key
]);
}
if
(
isset
(
$
obj
->
arrayFields
)
&&
is_array
(
$obj
->
arrayFields
))
{
foreach
(
$
obj
->
arrayFields
as
$key
)
if
(
isset
(
$
this
->
arrayFields
)
&&
is_array
(
$this
->
arrayFields
))
{
foreach
(
$
this
->
arrayFields
as
$key
)
$results
[
$key
]
=
explode
(
"|"
,
$results
[
$key
]);
}
if
(
static
::
$returnType
==
'Array'
)
...
...
@@ -135,17 +134,16 @@ abstract class dbObject {
return
$item
;
}
public
static
function
get
(
$limit
=
null
,
$fields
=
null
)
{
$obj
=
new
static
;
private
function
get
(
$limit
=
null
,
$fields
=
null
)
{
$objects
=
Array
();
$results
=
$
obj
->
db
->
get
(
$obj
->
dbTable
,
$limit
,
$fields
);
$results
=
$
this
->
db
->
get
(
$this
->
dbTable
,
$limit
,
$fields
);
foreach
(
$results
as
&
$r
)
{
if
(
isset
(
$
obj
->
jsonFields
)
&&
is_array
(
$obj
->
jsonFields
))
{
foreach
(
$
obj
->
jsonFields
as
$key
)
if
(
isset
(
$
this
->
jsonFields
)
&&
is_array
(
$this
->
jsonFields
))
{
foreach
(
$
this
->
jsonFields
as
$key
)
$r
[
$key
]
=
json_decode
(
$r
[
$key
]);
}
if
(
isset
(
$
obj
->
arrayFields
)
&&
is_array
(
$obj
->
arrayFields
))
{
foreach
(
$
obj
->
arrayFields
as
$key
)
if
(
isset
(
$
this
->
arrayFields
)
&&
is_array
(
$this
->
arrayFields
))
{
foreach
(
$
this
->
arrayFields
as
$key
)
$r
[
$key
]
=
explode
(
"|"
,
$r
[
$key
]);
}
if
(
static
::
$returnType
==
'Object'
)
{
...
...
@@ -173,19 +171,22 @@ abstract class dbObject {
return
$res
[
'cnt'
];
}
public
function
__call
(
$method
,
$arg
)
{
if
(
method_exists
(
$this
,
$method
))
return
call_user_func_array
(
array
(
$this
,
$method
),
$arg
);
call_user_func_array
(
array
(
$this
->
db
,
$method
),
$arg
);
return
$this
;
}
public
static
function
__callStatic
(
$method
,
$arg
)
{
$obj
=
new
static
;
call_user_func_array
(
array
(
$obj
,
$method
),
$arg
);
$result
=
call_user_func_array
(
array
(
$obj
,
$method
),
$arg
);
if
(
method_exists
(
$obj
,
$method
))
return
$result
;
return
$obj
;
}
public
function
toJson
()
{
return
json_encode
(
$this
->
data
);
}
...
...
dbObject/test.php
View file @
d2aa5131
...
...
@@ -14,6 +14,7 @@ $dept->name = 'avb test';
$dept
->
authcode
=
Array
(
'1234'
,
'123456'
);
$dept
->
iscallerid
=
1
;
$dept
->
insert
();
echo
"ID = "
.
$dept
->
id
.
"
\n
"
;
$dept2
=
new
department
([
'userid'
=>
'11'
,
...
...
@@ -25,29 +26,36 @@ $dept2->save();
$dept2
->
iscallerid
=
1
;
print_r
(
$dept2
->
data
);
$dept2
->
save
();
echo
"department is of class "
.
get_class
(
$dept2
)
.
"
\n
"
;
echo
"List
\n
"
;
$depts
=
department
::
get
();
foreach
(
$depts
as
$d
)
{
// print_r ($d->data);
echo
$d
.
"
\n
"
;
echo
"department is of class "
.
get_class
(
$d
)
.
"
\n
"
;
}
echo
"getOne
\n
"
;
$dept3
=
department
::
byId
(
"181"
);
$dept3
=
department
::
byId
(
$dept
->
id
);
echo
'cnt '
.
$dept3
->
count
.
"
\n
"
;
$dept3
->
authcode
=
33
3
;
$dept3
->
authcode
=
44
3
;
$dept3
->
save
();
print_r
(
$dept3
->
data
)
.
"
\n
"
;
echo
"department is of class "
.
get_class
(
$dept3
)
.
"
\n
"
;
echo
"hasOne
\n
"
;
echo
json_encode
(
$dept3
->
userid
->
data
);
echo
"user is of class "
.
get_class
(
$dept3
->
userid
)
.
"
\n
"
;
echo
"
\n
hasMany
\n
"
;
foreach
(
$dept3
->
userid
->
departments
as
$d
)
{
echo
$d
;
echo
"department is of class "
.
get_class
(
$d
)
.
"
\n
"
;
}
$user
=
user
::
byId
(
41
);
echo
"user is of class "
.
get_class
(
$user
)
.
"
\n
"
;
?>
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