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
ea35ad41
Commit
ea35ad41
authored
Jul 24, 2015
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not connect to mysql in __construct
parent
dd69e990
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
21 deletions
+35
-21
MysqliDb.php
MysqliDb.php
+29
-21
mysqliDbTests.php
tests/mysqliDbTests.php
+6
-0
No files found.
MysqliDb.php
View file @
ea35ad41
...
...
@@ -167,11 +167,6 @@ 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
();
self
::
$_instance
=
$this
;
}
...
...
@@ -192,8 +187,19 @@ class MysqliDb
or
die
(
'There was a problem connecting to the database'
);
if
(
$this
->
charset
)
$this
->
_mysqli
->
set_charset
(
$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 +649,7 @@ class MysqliDb
*/
public
function
getInsertId
()
{
return
$this
->
_mysqli
->
insert_id
;
return
$this
->
mysqli
()
->
insert_id
;
}
/**
...
...
@@ -655,7 +661,7 @@ class MysqliDb
*/
public
function
escape
(
$str
)
{
return
$this
->
_mysqli
->
real_escape_string
(
$str
);
return
$this
->
mysqli
()
->
real_escape_string
(
$str
);
}
/**
...
...
@@ -667,7 +673,7 @@ class MysqliDb
* @return bool True if connection is up
*/
public
function
ping
()
{
return
$this
->
_mysqli
->
ping
();
return
$this
->
mysqli
()
->
ping
();
}
/**
...
...
@@ -876,11 +882,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 +1080,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
);
...
...
@@ -1091,7 +1097,7 @@ class MysqliDb
if
(
!
$this
->
isSubQuery
)
return
;
if
(
$this
->
_mysqli
)
$this
->
_mysqli
->
close
();
$this
->
mysqli
()
->
close
();
}
/**
...
...
@@ -1151,7 +1157,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 +1284,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 +1296,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 +1308,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 @
ea35ad41
...
...
@@ -112,6 +112,12 @@ foreach ($tables as $name => $fields) {
createTable
(
$prefix
.
$name
,
$fields
);
}
if
(
!
$db
->
ping
())
{
echo
"db is not up"
;
exit
;
}
$str
=
$db
->
escape
(
"te'st"
);
// 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