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
22b45157
Commit
22b45157
authored
Jul 27, 2015
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #271 from avbdr/master
fixes
parents
cdd185b5
493c1886
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
25 deletions
+38
-25
MysqliDb.php
MysqliDb.php
+30
-21
mysqliDbTests.php
tests/mysqliDbTests.php
+8
-4
No files found.
MysqliDb.php
View file @
22b45157
...
...
@@ -24,7 +24,7 @@ class MysqliDb
*
* @var string
*/
public
static
$prefix
;
public
static
$prefix
=
''
;
/**
* MySQLi instance
*
...
...
@@ -167,12 +167,8 @@ class MysqliDb
$this
->
isSubQuery
=
true
;
return
;
}
// for subqueries we do not need database connection and redefine root instance
if
(
!
is_object
(
$host
))
$this
->
connect
();
$this
->
setPrefix
();
if
(
isset
(
$prefix
))
$this
->
setPrefix
(
$prefix
);
self
::
$_instance
=
$this
;
}
...
...
@@ -194,6 +190,17 @@ class MysqliDb
if
(
$this
->
charset
)
$this
->
_mysqli
->
set_charset
(
$this
->
charset
);
}
/**
* A method to get mysqli object or create it in case needed
*/
public
function
mysqli
()
{
if
(
!
$this
->
_mysqli
)
$this
->
connect
();
return
$this
->
_mysqli
;
}
/**
* A method of returning the static instance to allow access to the
* instantiated object from within another class.
...
...
@@ -643,7 +650,7 @@ class MysqliDb
*/
public
function
getInsertId
()
{
return
$this
->
_mysqli
->
insert_id
;
return
$this
->
mysqli
()
->
insert_id
;
}
/**
...
...
@@ -655,7 +662,7 @@ class MysqliDb
*/
public
function
escape
(
$str
)
{
return
$this
->
_mysqli
->
real_escape_string
(
$str
);
return
$this
->
mysqli
()
->
real_escape_string
(
$str
);
}
/**
...
...
@@ -667,7 +674,7 @@ class MysqliDb
* @return bool True if connection is up
*/
public
function
ping
()
{
return
$this
->
_mysqli
->
ping
();
return
$this
->
mysqli
()
->
ping
();
}
/**
...
...
@@ -876,11 +883,11 @@ class MysqliDb
array_push
(
$results
,
$x
);
}
// stored procedures sometimes can return more then 1 resultset
if
(
$this
->
_mysqli
->
more_results
())
$this
->
_mysqli
->
next_result
();
if
(
$this
->
mysqli
()
->
more_results
())
$this
->
mysqli
()
->
next_result
();
if
(
in_array
(
'SQL_CALC_FOUND_ROWS'
,
$this
->
_queryOptions
))
{
$stmt
=
$this
->
_mysqli
->
query
(
'SELECT FOUND_ROWS()'
);
$stmt
=
$this
->
mysqli
()
->
query
(
'SELECT FOUND_ROWS()'
);
$totalCount
=
$stmt
->
fetch_row
();
$this
->
totalCount
=
$totalCount
[
0
];
}
...
...
@@ -1074,8 +1081,8 @@ class MysqliDb
*/
protected
function
_prepareQuery
()
{
if
(
!
$stmt
=
$this
->
_mysqli
->
prepare
(
$this
->
_query
))
{
trigger_error
(
"Problem preparing query (
$this->_query
) "
.
$this
->
_mysqli
->
error
,
E_USER_ERROR
);
if
(
!
$stmt
=
$this
->
mysqli
()
->
prepare
(
$this
->
_query
))
{
trigger_error
(
"Problem preparing query (
$this->_query
) "
.
$this
->
mysqli
()
->
error
,
E_USER_ERROR
);
}
if
(
$this
->
traceEnabled
)
$this
->
traceStartQ
=
microtime
(
true
);
...
...
@@ -1151,7 +1158,9 @@ class MysqliDb
* @return string
*/
public
function
getLastError
()
{
return
trim
(
$this
->
_stmtError
.
" "
.
$this
->
_mysqli
->
error
);
if
(
!
$this
->
_mysqli
)
return
"mysqli is null"
;
return
trim
(
$this
->
_stmtError
.
" "
.
$this
->
mysqli
()
->
error
);
}
/**
...
...
@@ -1276,7 +1285,7 @@ class MysqliDb
* @uses register_shutdown_function(array($this, "_transaction_shutdown_check"))
*/
public
function
startTransaction
()
{
$this
->
_mysqli
->
autocommit
(
false
);
$this
->
mysqli
()
->
autocommit
(
false
);
$this
->
_transaction_in_progress
=
true
;
register_shutdown_function
(
array
(
$this
,
"_transaction_status_check"
));
}
...
...
@@ -1288,9 +1297,9 @@ class MysqliDb
* @uses mysqli->autocommit(true);
*/
public
function
commit
()
{
$this
->
_mysqli
->
commit
();
$this
->
mysqli
()
->
commit
();
$this
->
_transaction_in_progress
=
false
;
$this
->
_mysqli
->
autocommit
(
true
);
$this
->
mysqli
()
->
autocommit
(
true
);
}
/**
...
...
@@ -1300,9 +1309,9 @@ class MysqliDb
* @uses mysqli->autocommit(true);
*/
public
function
rollback
()
{
$this
->
_mysqli
->
rollback
();
$this
->
mysqli
()
->
rollback
();
$this
->
_transaction_in_progress
=
false
;
$this
->
_mysqli
->
autocommit
(
true
);
$this
->
mysqli
()
->
autocommit
(
true
);
}
/**
...
...
tests/mysqliDbTests.php
View file @
22b45157
...
...
@@ -2,6 +2,7 @@
require_once
(
"../MysqliDb.php"
);
error_reporting
(
E_ALL
);
$prefix
=
't_'
;
$db
=
new
Mysqlidb
(
'localhost'
,
'root'
,
''
,
'testdb'
);
if
(
!
$db
)
die
(
"Database error"
);
...
...
@@ -12,13 +13,11 @@ $db = new Mysqlidb(Array (
'host'
=>
'localhost'
,
'username'
=>
'root'
,
'password'
=>
''
,
'db'
=>
'testdb'
,
'db'
=>
'testdb'
,
'prefix'
=>
$prefix
,
'charset'
=>
null
));
if
(
!
$db
)
die
(
"Database error"
);
$prefix
=
't_'
;
$db
->
setPrefix
(
$prefix
);
$db
->
setTrace
(
true
);
$tables
=
Array
(
...
...
@@ -112,6 +111,11 @@ foreach ($tables as $name => $fields) {
createTable
(
$prefix
.
$name
,
$fields
);
}
if
(
!
$db
->
ping
())
{
echo
"db is not up"
;
exit
;
}
// insert test with autoincrement
foreach
(
$data
as
$name
=>
$datas
)
{
foreach
(
$datas
as
$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