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
79a83d07
Commit
79a83d07
authored
May 12, 2015
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new dbObject class
parent
97c09d9f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
0 deletions
+140
-0
dbObject.php
dbObject.php
+108
-0
accData.php
dbObject/models/accData.php
+15
-0
test.php
dbObject/test.php
+17
-0
No files found.
dbObject.php
0 → 100644
View file @
79a83d07
<?php
abstract
class
dbObject
{
public
$db
;
public
function
__construct
()
{
$this
->
db
=
MysqliDb
::
getInstance
();
}
private
function
cleanup
(
$data
)
{
if
(
method_exists
(
$this
,
"preLoad"
))
$this
->
preLoad
(
$data
);
if
(
count
(
$data
)
==
0
)
return
Array
();
foreach
(
$this
->
dbFields
as
$key
=>
$prop
)
{
$value
=
$data
[
$key
];
if
(
!
is_array
(
$value
))
{
$sqlData
[
$key
]
=
$value
;
continue
;
}
if
(
$prop
[
'json'
])
$sqlData
[
$key
]
=
json_encode
(
$value
);
else
if
(
$prop
[
'array'
])
$sqlData
[
$key
]
=
implode
(
"|"
,
$value
);
else
$sqlData
[
$key
]
=
$value
;
}
return
$sqlData
;
}
public
function
insert
(
&
$data
)
{
if
(
empty
(
$this
->
dbFields
))
return
false
;
$data
=
$this
->
cleanup
(
$data
);
$id
=
$this
->
db
->
insert
(
$this
->
dbTable
,
$data
);
$data
[
$this
->
$primaryKey
]
=
$id
;
return
$id
;
}
public
function
remove
(
$data
)
{
$this
->
db
->
where
(
$this
->
primaryKey
,
$data
[
'id'
]);
return
$this
->
db
->
delete
(
$this
->
dbTable
);
}
public
function
update
(
$data
)
{
if
(
empty
(
$this
->
dbFields
))
return
false
;
$data
=
$this
->
cleanup
(
$data
);
$this
->
db
->
where
(
$this
->
primaryKey
,
$data
[
$this
->
primaryKey
]);
return
$this
->
db
->
update
(
$this
->
dbTable
,
$data
);
}
public
function
getOne
(
$id
,
$fields
=
null
)
{
$this
->
db
->
where
(
$this
->
primaryKey
,
$id
);
$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
(
$this
->
arrayFields
)
&&
is_array
(
$this
->
arrayFields
))
{
foreach
(
$this
->
arrayFields
as
$key
)
$results
[
$key
]
=
explode
(
"|"
,
$results
[
$key
]);
}
return
$results
;
}
public
function
get
(
$limit
=
null
,
$fields
=
null
)
{
$db
=
MysqliDb
::
getInstance
();
$results
=
$db
->
get
(
$this
->
dbTable
);
foreach
(
$results
as
&
$r
)
{
if
(
isset
(
$this
->
jsonFields
)
&&
is_array
(
$this
->
jsonFields
))
{
foreach
(
$this
->
jsonFields
as
$key
)
$r
[
$key
]
=
json_decode
(
$r
[
$key
]);
}
if
(
isset
(
$this
->
arrayFields
)
&&
is_array
(
$this
->
arrayFields
))
{
foreach
(
$this
->
arrayFields
as
$key
)
$r
[
$key
]
=
explode
(
"|"
,
$r
[
$key
]);
}
}
return
$results
;
}
public
function
where
(
$whereProp
,
$whereValue
=
null
,
$operator
=
null
)
{
$this
->
db
->
where
(
$whereProp
,
$whereValue
,
$operator
);
return
$this
;
}
public
function
orWhere
(
$whereProp
,
$whereValue
=
null
,
$operator
=
null
)
{
$this
->
db
->
orWhere
(
$whereProp
,
$whereValue
,
$operator
);
return
$this
;
}
public
function
orderBy
(
$orderByField
,
$orderbyDirection
=
"DESC"
,
$customFields
=
null
)
{
$this
->
db
->
orderBy
(
$orderByField
,
$orderbyDirection
,
$customFields
);
return
$this
;
}
public
function
count
()
{
$res
=
$this
->
db
->
getValue
(
$this
->
dbTable
,
"count(*)"
);
return
$res
[
'cnt'
];
}
}
?>
dbObject/models/accData.php
0 → 100644
View file @
79a83d07
<?php
require_once
"../dbObject.php"
;
class
accData
extends
dbObject
{
protected
$dbTable
=
"acc_data"
;
protected
$primaryKey
=
"id"
;
public
function
last
()
{
$this
->
db
->
where
(
"id"
,
1300
,
'>'
);
return
$this
;
}
}
?>
dbObject/test.php
0 → 100644
View file @
79a83d07
<?
require_once
(
"../MysqliDb.php"
);
require_once
(
"models/accData.php"
);
$db
=
new
Mysqlidb
(
'localhost'
,
'root'
,
''
,
'akorbi'
);
$accData
=
new
accData
();
$d
=
$accData
->
getOne
(
1288
);
print_r
(
$d
);
print_r
(
$accData
->
last
()
->
get
());
//$a = new accData;
?>
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