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
8e45c952
Commit
8e45c952
authored
Aug 04, 2015
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trim whitespaces in the code
parent
20db85d5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
32 deletions
+32
-32
MysqliDb.php
MysqliDb.php
+30
-30
mysqliDbTests.php
tests/mysqliDbTests.php
+2
-2
No files found.
MysqliDb.php
View file @
8e45c952
...
...
@@ -21,7 +21,7 @@ class MysqliDb
protected
static
$_instance
;
/**
* Table prefix
*
*
* @var string
*/
public
static
$prefix
=
''
;
...
...
@@ -54,7 +54,7 @@ class MysqliDb
*
* @var array
*/
protected
$_join
=
array
();
protected
$_join
=
array
();
/**
* An array that holds where conditions 'fieldname' => 'value'
*
...
...
@@ -64,11 +64,11 @@ class MysqliDb
/**
* Dynamic type list for order by condition value
*/
protected
$_orderBy
=
array
();
protected
$_orderBy
=
array
();
/**
* Dynamic type list for group by condition value
*/
protected
$_groupBy
=
array
();
protected
$_groupBy
=
array
();
/**
* Dynamic array that holds a combination of where condition/table data value types and parameter references
*
...
...
@@ -79,13 +79,13 @@ class MysqliDb
* Variable which holds an amount of returned rows during get/getOne/select queries
*
* @var string
*/
*/
public
$count
=
0
;
/**
* Variable which holds an amount of returned rows during get/getOne/select queries with withTotalCount()
*
* @var string
*/
*/
public
$totalCount
=
0
;
/**
* Variable which holds last statement error
...
...
@@ -113,7 +113,7 @@ class MysqliDb
protected
$isSubQuery
=
false
;
/**
* Name of the auto increment column
* Name of the auto increment column
*
*/
protected
$_lastInsertId
=
null
;
...
...
@@ -240,7 +240,7 @@ class MysqliDb
$this
->
_where
=
array
();
$this
->
_join
=
array
();
$this
->
_orderBy
=
array
();
$this
->
_groupBy
=
array
();
$this
->
_groupBy
=
array
();
$this
->
_bindParams
=
array
(
''
);
// Create the empty 0 index
$this
->
_query
=
null
;
$this
->
_queryOptions
=
array
();
...
...
@@ -281,10 +281,10 @@ class MysqliDb
$this
->
returnType
=
'Object'
;
return
$this
;
}
/**
* Method to set a prefix
*
*
* @param string $prefix Contains a tableprefix
*/
public
function
setPrefix
(
$prefix
=
''
)
...
...
@@ -399,7 +399,7 @@ class MysqliDb
if
(
empty
(
$columns
))
$columns
=
'*'
;
$column
=
is_array
(
$columns
)
?
implode
(
', '
,
$columns
)
:
$columns
;
$column
=
is_array
(
$columns
)
?
implode
(
', '
,
$columns
)
:
$columns
;
$this
->
_tableName
=
self
::
$prefix
.
$tableName
;
$this
->
_query
=
'SELECT '
.
implode
(
' '
,
$this
->
_queryOptions
)
.
' '
.
$column
.
" FROM "
.
$this
->
_tableName
;
...
...
@@ -423,7 +423,7 @@ class MysqliDb
*
* @return array Contains the returned rows from the select query.
*/
public
function
getOne
(
$tableName
,
$columns
=
'*'
)
public
function
getOne
(
$tableName
,
$columns
=
'*'
)
{
$res
=
$this
->
get
(
$tableName
,
1
,
$columns
);
...
...
@@ -444,7 +444,7 @@ class MysqliDb
*
* @return string Contains the value of a returned column.
*/
public
function
getValue
(
$tableName
,
$column
)
public
function
getValue
(
$tableName
,
$column
)
{
$res
=
$this
->
ArrayBuilder
()
->
get
(
$tableName
,
1
,
"
{
$column
}
as retval"
);
...
...
@@ -563,12 +563,12 @@ class MysqliDb
return
$this
;
}
/**
* This function store update column's name and column name of the
/**
* This function store update column's name and column name of the
* autoincrement column
*
*
* @param Array Variable with values
* @param String Variable value
* @param String Variable value
*/
public
function
onDuplicate
(
$_updateColumns
,
$_lastInsertId
=
null
)
{
...
...
@@ -632,7 +632,7 @@ class MysqliDb
$orderbyDirection
=
strtoupper
(
trim
(
$orderbyDirection
));
$orderByField
=
preg_replace
(
"/[^-a-z0-9\.\(\),_`]+/i"
,
''
,
$orderByField
);
// Add table prefix to orderByField if needed.
// Add table prefix to orderByField if needed.
//FIXME: We are adding prefix only if table is enclosed into `` to distinguish aliases
// from table names
$orderByField
=
preg_replace
(
'/(\`)([`a-zA-Z0-9_]*\.)/'
,
'\1'
.
self
::
$prefix
.
'\2'
,
$orderByField
);
...
...
@@ -650,7 +650,7 @@ class MysqliDb
$this
->
_orderBy
[
$orderByField
]
=
$orderbyDirection
;
return
$this
;
}
}
/**
* This method allows you to specify multiple (method chaining optional) GROUP BY statements for SQL queries.
...
...
@@ -667,7 +667,7 @@ class MysqliDb
$this
->
_groupBy
[]
=
$groupByField
;
return
$this
;
}
}
/**
* This methods returns the ID of the last inserted item
...
...
@@ -805,9 +805,9 @@ class MysqliDb
return
true
;
}
/**
/**
* Helper function to add variables into the query statement
*
*
* @param Array Variable with values
*/
protected
function
_buildDuplicate
(
$tableData
)
...
...
@@ -815,20 +815,20 @@ class MysqliDb
if
(
is_array
(
$this
->
_updateColumns
)
&&
!
empty
(
$this
->
_updateColumns
))
{
$this
->
_query
.=
" on duplicate key update "
;
if
(
$this
->
_lastInsertId
)
{
$this
->
_lastQuery
.=
$this
->
_lastInsertId
.
"=LAST_INSERT_ID("
.
$this
->
_lastInsertId
.
"),"
;
$this
->
_lastQuery
.=
$this
->
_lastInsertId
.
"=LAST_INSERT_ID
("
.
$this
->
_lastInsertId
.
"),"
;
$this
->
_lastInsertId
=
null
;
}
foreach
(
$this
->
_updateColumns
as
$column
)
{
$this
->
_query
.=
"`"
.
$column
.
"` = "
;
// Simple value
if
(
!
is_array
(
$tableData
[
$column
]))
{
$this
->
_bindParam
(
$tableData
[
$column
]);
$this
->
_query
.=
'?, '
;
continue
;
}
// Function value
$arr
=
$tableData
[
$column
];
$key
=
key
(
$arr
);
...
...
@@ -912,7 +912,7 @@ class MysqliDb
// if $meta is false yet sqlstate is true, there's no sql error but the query is
// most likely an update/insert/delete which doesn't produce any results
if
(
!
$meta
&&
$stmt
->
sqlstate
)
{
if
(
!
$meta
&&
$stmt
->
sqlstate
)
{
return
array
();
}
...
...
@@ -1234,7 +1234,7 @@ class MysqliDb
/**
* Method returns mysql error
*
*
* @return string
*/
public
function
getLastError
()
{
...
...
@@ -1246,7 +1246,7 @@ class MysqliDb
/**
* Mostly internal method to get query and its params out of subquery object
* after get() and getAll()
*
*
* @return array
*/
public
function
getSubQuery
()
{
...
...
@@ -1321,7 +1321,7 @@ class MysqliDb
public
function
dec
(
$num
=
1
)
{
return
Array
(
"[I]"
=>
"-"
.
(
int
)
$num
);
}
/**
* Method generates change boolean function call
* @param string column name. null by default
...
...
tests/mysqliDbTests.php
View file @
8e45c952
...
...
@@ -11,7 +11,7 @@ $db = new Mysqlidb($mysqli);
$db
=
new
Mysqlidb
(
Array
(
'host'
=>
'localhost'
,
'username'
=>
'root'
,
'username'
=>
'root'
,
'password'
=>
''
,
'db'
=>
'testdb'
,
'prefix'
=>
$prefix
,
...
...
@@ -380,7 +380,7 @@ if ($db->totalCount != 3) {
$db
->
delete
(
"users"
);
$db
->
get
(
"users"
);
if
(
$db
->
count
!=
0
)
{
echo
"Invalid users count after delete"
;
echo
"Invalid users count after delete"
;
exit
;
}
$db
->
delete
(
"products"
);
...
...
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