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
682f3bea
Commit
682f3bea
authored
Aug 11, 2013
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Input variables validation
parent
e215dad1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
8 deletions
+22
-8
MysqliDb.php
MysqliDb.php
+22
-8
No files found.
MysqliDb.php
View file @
682f3bea
...
...
@@ -175,9 +175,13 @@ class MysqliDb
*
* @return array Contains the returned rows from the select query.
*/
public
function
get
(
$tableName
,
$numRows
=
null
)
public
function
get
(
$tableName
,
$numRows
=
null
,
$columns
=
'*'
)
{
$this
->
_query
=
"SELECT * FROM
$tableName
"
;
if
(
empty
(
$columns
))
$columns
=
'*'
;
$column
=
is_array
(
$columns
)
?
implode
(
', '
,
$columns
)
:
$columns
;
$this
->
_query
=
"SELECT
$column
FROM
$tableName
"
;
$stmt
=
$this
->
_buildQuery
(
$numRows
);
$stmt
->
execute
();
$this
->
reset
();
...
...
@@ -192,9 +196,9 @@ class MysqliDb
*
* @return array Contains the returned rows from the select query.
*/
public
function
getOne
(
$tableName
)
public
function
getOne
(
$tableName
,
$columns
=
'*'
)
{
$res
=
$this
->
get
(
$tableName
,
1
);
$res
=
$this
->
get
(
$tableName
,
1
,
$columns
);
return
$res
[
0
];
}
...
...
@@ -283,13 +287,14 @@ class MysqliDb
public
function
join
(
$joinTable
,
$joinCondition
,
$joinType
=
''
)
{
$allowedTypes
=
array
(
'LEFT'
,
'RIGHT'
,
'OUTER'
,
'INNER'
,
'LEFT OUTER'
,
'RIGHT OUTER'
);
$joinType
=
strtoupper
(
trim
(
$joinType
));
$joinTable
=
filter_var
(
$joinTable
,
FILTER_SANITIZE_STRING
);
if
(
$joinType
&&
in_array
(
$joinType
,
$allowedTypes
))
$joinType
=
strtoupper
(
trim
(
$joinType
));
else
$joinType
=
''
;
if
(
$joinType
&&
!
in_array
(
$joinType
,
$allowedTypes
))
die
(
'Wrong JOIN type: '
.
$joinType
);
$this
->
_join
[
$joinType
.
" JOIN "
.
$joinTable
]
=
$joinCondition
;
return
$this
;
}
/**
...
...
@@ -304,6 +309,13 @@ class MysqliDb
*/
public
function
orderBy
(
$orderByField
,
$orderbyDirection
)
{
$allowedDirection
=
Array
(
"ASC"
,
"DESC"
);
$orderbyDirection
=
strtoupper
(
trim
(
$orderbyDirection
));
$orderByField
=
filter_var
(
$orderByField
,
FILTER_SANITIZE_STRING
);
if
(
empty
(
$orderbyDirection
)
||
!
in_array
(
$orderbyDirection
,
$allowedDirection
))
die
(
'Wrong order direction: '
.
$orderbyDirection
);
$this
->
_orderBy
[
$orderByField
]
=
$orderbyDirection
;
return
$this
;
}
...
...
@@ -319,6 +331,8 @@ class MysqliDb
*/
public
function
groupBy
(
$groupByField
)
{
$groupByField
=
filter_var
(
$groupByField
,
FILTER_SANITIZE_STRING
);
$this
->
_groupBy
[]
=
$groupByField
;
return
$this
;
}
...
...
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