Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
outils
question2answer
Commits
2a6d8fab
Commit
2a6d8fab
authored
Jan 19, 2019
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix qa_db_connection and auto-connect in DbConnection
parent
915ee0a9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
2 deletions
+20
-2
qa-db.php
qa-include/qa-db.php
+6
-1
DbConnection.php
qa-src/Database/DbConnection.php
+14
-1
No files found.
qa-include/qa-db.php
View file @
2a6d8fab
...
@@ -80,7 +80,12 @@ function qa_db_connection($connect = true)
...
@@ -80,7 +80,12 @@ function qa_db_connection($connect = true)
{
{
if
(
qa_to_override
(
__FUNCTION__
))
{
$args
=
func_get_args
();
return
qa_call_override
(
__FUNCTION__
,
$args
);
}
if
(
qa_to_override
(
__FUNCTION__
))
{
$args
=
func_get_args
();
return
qa_call_override
(
__FUNCTION__
,
$args
);
}
return
qa_service
(
'database'
);
$db
=
qa_service
(
'database'
);
if
(
$connect
&&
!
$db
->
isConnected
())
{
$db
->
connect
();
}
return
$db
;
}
}
...
...
qa-src/Database/DbConnection.php
View file @
2a6d8fab
...
@@ -82,6 +82,15 @@ class DbConnection
...
@@ -82,6 +82,15 @@ class DbConnection
}
}
/**
/**
* Indicates whether Q2A is connected to the database.
* @return boolean
*/
public
function
isConnected
()
{
return
$this
->
pdo
!==
null
;
}
/**
* Connect to the Q2A database, optionally install the $failHandler (and call it if necessary). Uses PDO as of Q2A
* Connect to the Q2A database, optionally install the $failHandler (and call it if necessary). Uses PDO as of Q2A
* 1.9.
* 1.9.
* @param string $failHandler
* @param string $failHandler
...
@@ -124,7 +133,7 @@ class DbConnection
...
@@ -124,7 +133,7 @@ class DbConnection
}
}
/**
/**
* Disconnect from the Q2A database.
* Disconnect from the Q2A database.
This is not strictly required, but we do it in case there is a long Q2A shutdown process.
* @return void
* @return void
*/
*/
public
function
disconnect
()
public
function
disconnect
()
...
@@ -166,6 +175,10 @@ class DbConnection
...
@@ -166,6 +175,10 @@ class DbConnection
*/
*/
public
function
query
(
$query
,
$params
=
array
())
public
function
query
(
$query
,
$params
=
array
())
{
{
if
(
!
$this
->
isConnected
())
{
$this
->
connect
();
}
$query
=
$this
->
applyTableSub
(
$query
);
$query
=
$this
->
applyTableSub
(
$query
);
// handle old-style placeholders
// handle old-style placeholders
$query
=
str_replace
([
'#'
,
'$'
],
'?'
,
$query
);
$query
=
str_replace
([
'#'
,
'$'
],
'?'
,
$query
);
...
...
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