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
bf235793
Commit
bf235793
authored
Sep 28, 2015
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #332 from avbdr/master
fixes
parents
e0153d7f
12c0a1db
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
17 deletions
+30
-17
MysqliDb.php
MysqliDb.php
+2
-2
dbObject.php
dbObject.php
+22
-15
dbObjectTests.php
tests/dbObjectTests.php
+6
-0
No files found.
MysqliDb.php
View file @
bf235793
...
...
@@ -396,7 +396,7 @@ class MysqliDb
*/
public
function
query
(
$query
,
$numRows
=
null
)
{
$this
->
_query
=
filter_var
(
$query
,
FILTER_SANITIZE_STRING
)
;
$this
->
_query
=
$query
;
$stmt
=
$this
->
_buildQuery
(
$numRows
);
$stmt
->
execute
();
$this
->
_stmtError
=
$stmt
->
error
;
...
...
@@ -694,7 +694,7 @@ class MysqliDb
die
(
'Wrong JOIN type: '
.
$joinType
);
if
(
!
is_object
(
$joinTable
))
$joinTable
=
self
::
$prefix
.
filter_var
(
$joinTable
,
FILTER_SANITIZE_STRING
)
;
$joinTable
=
self
::
$prefix
.
$joinTable
;
$this
->
_join
[]
=
Array
(
$joinType
,
$joinTable
,
$joinCondition
);
...
...
dbObject.php
View file @
bf235793
...
...
@@ -11,6 +11,9 @@
* @version 2.2
*
* @method int count ()
* @method dbObject ArrayBuilder()
* @method dbObject JsonBuilder()
* @method dbObject ObjectBuilder()
* @method mixed byId (string $id, mixed $fields)
* @method mixed get (mixed $limit, mixed $fields)
* @method mixed getOne (mixed $fields)
...
...
@@ -181,10 +184,9 @@ class dbObject {
*
* @return dbObject
*/
public
static
function
JsonBuilder
()
{
$obj
=
new
static
;
$obj
->
returnType
=
'Json'
;
return
$obj
;
private
function
JsonBuilder
()
{
$this
->
returnType
=
'Json'
;
return
$return
;
}
/**
...
...
@@ -192,10 +194,9 @@ class dbObject {
*
* @return dbObject
*/
public
static
function
ArrayBuilder
()
{
$obj
=
new
static
;
$obj
->
returnType
=
'Array'
;
return
$obj
;
private
function
ArrayBuilder
()
{
$this
->
returnType
=
'Array'
;
return
$this
;
}
/**
...
...
@@ -204,8 +205,9 @@ class dbObject {
*
* @return dbObject
*/
public
static
function
ObjectBuilder
()
{
return
new
static
;
private
function
ObjectBuilder
()
{
$this
->
returnType
=
'Object'
;
return
$this
;
}
/**
...
...
@@ -297,7 +299,7 @@ class dbObject {
*
* @return dbObject|array
*/
pr
ivate
function
byId
(
$id
,
$fields
=
null
)
{
pr
otected
function
byId
(
$id
,
$fields
=
null
)
{
$this
->
db
->
where
(
MysqliDb
::
$prefix
.
$this
->
dbTable
.
'.'
.
$this
->
primaryKey
,
$id
);
return
$this
->
getOne
(
$fields
);
}
...
...
@@ -310,7 +312,7 @@ class dbObject {
*
* @return dbObject
*/
pr
ivate
function
getOne
(
$fields
=
null
)
{
pr
otected
function
getOne
(
$fields
=
null
)
{
$this
->
processHasOneWith
();
$results
=
$this
->
db
->
ArrayBuilder
()
->
getOne
(
$this
->
dbTable
,
$fields
);
if
(
$this
->
db
->
count
==
0
)
...
...
@@ -340,7 +342,7 @@ class dbObject {
*
* @return array Array of dbObjects
*/
pr
ivate
function
get
(
$limit
=
null
,
$fields
=
null
)
{
pr
otected
function
get
(
$limit
=
null
,
$fields
=
null
)
{
$objects
=
Array
();
$this
->
processHasOneWith
();
$results
=
$this
->
db
->
ArrayBuilder
()
->
get
(
$this
->
dbTable
,
$limit
,
$fields
);
...
...
@@ -409,9 +411,11 @@ class dbObject {
*
* @return int
*/
pr
ivate
function
count
()
{
pr
otected
function
count
()
{
$res
=
$this
->
db
->
ArrayBuilder
()
->
getValue
(
$this
->
dbTable
,
"count(*)"
);
return
$res
[
'cnt'
];
if
(
!
$res
)
return
0
;
return
$res
;
}
/**
...
...
@@ -608,6 +612,9 @@ class dbObject {
case
"int"
:
$regexp
=
"/^[0-9]*$/"
;
break
;
case
"double"
:
$regexp
=
"/^[0-9\.]*$/"
;
break
;
case
"bool"
:
$regexp
=
'/^[yes|no|0|1|true|false]$/i'
;
break
;
...
...
tests/dbObjectTests.php
View file @
bf235793
...
...
@@ -141,6 +141,12 @@ if (!is_array ($products[0]['userId']) || !is_array ($products[1]['userId'])) {
exit
;
}
$products
=
product
::
with
(
'userId'
)
->
ArrayBuilder
()
->
get
(
2
);
if
(
!
is_array
(
$products
[
0
][
'userId'
])
||
!
is_array
(
$products
[
1
][
'userId'
]))
{
echo
"Error in with processing in get"
;
exit
;
}
$depts
=
product
::
join
(
'user'
)
->
orderBy
(
'`products`.id'
,
'desc'
)
->
get
(
5
);
foreach
(
$depts
as
$d
)
{
if
(
!
is_object
(
$d
))
{
...
...
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