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
b8d37584
Commit
b8d37584
authored
Jan 18, 2019
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor DbConnection tweaks
parent
10e8e762
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
DbConnection.php
qa-src/Database/DbConnection.php
+12
-3
DbResult.php
qa-src/Database/DbResult.php
+2
-2
No files found.
qa-src/Database/DbConnection.php
View file @
b8d37584
...
@@ -104,7 +104,10 @@ class DbConnection
...
@@ -104,7 +104,10 @@ class DbConnection
$dsn
.=
';port='
.
$this
->
config
[
'port'
];
$dsn
.=
';port='
.
$this
->
config
[
'port'
];
}
}
$options
=
array
(
PDO
::
ATTR_ERRMODE
=>
PDO
::
ERRMODE_EXCEPTION
);
$options
=
array
(
PDO
::
ATTR_ERRMODE
=>
PDO
::
ERRMODE_EXCEPTION
,
PDO
::
ATTR_EMULATE_PREPARES
=>
true
,
// required for queries like LOCK TABLES (also, slightly faster)
);
if
(
QA_PERSISTENT_CONN_DB
)
{
if
(
QA_PERSISTENT_CONN_DB
)
{
$options
[
PDO
::
ATTR_PERSISTENT
]
=
true
;
$options
[
PDO
::
ATTR_PERSISTENT
]
=
true
;
}
}
...
@@ -140,7 +143,8 @@ class DbConnection
...
@@ -140,7 +143,8 @@ class DbConnection
@
error_log
(
'PHP Question2Answer MySQL '
.
$type
.
' error '
.
$errno
.
': '
.
$error
.
(
isset
(
$query
)
?
(
' - Query: '
.
$query
)
:
''
));
@
error_log
(
'PHP Question2Answer MySQL '
.
$type
.
' error '
.
$errno
.
': '
.
$error
.
(
isset
(
$query
)
?
(
' - Query: '
.
$query
)
:
''
));
if
(
function_exists
(
$this
->
failHandler
))
{
if
(
function_exists
(
$this
->
failHandler
))
{
$this
->
failHandler
(
$type
,
$errno
,
$error
,
$query
);
$failFunc
=
$this
->
failHandler
;
$failFunc
(
$type
,
$errno
,
$error
,
$query
);
}
else
{
}
else
{
echo
sprintf
(
echo
sprintf
(
'<hr><div style="color: red">Database %s<p>%s</p><code>%s</code></div>'
,
'<hr><div style="color: red">Database %s<p>%s</p><code>%s</code></div>'
,
...
@@ -192,9 +196,14 @@ class DbConnection
...
@@ -192,9 +196,14 @@ class DbConnection
protected
function
execute
(
$query
,
$params
=
array
())
protected
function
execute
(
$query
,
$params
=
array
())
{
{
$stmt
=
$this
->
pdo
->
prepare
(
$query
);
$stmt
=
$this
->
pdo
->
prepare
(
$query
);
// PDO quotes parameters by default, which breaks LIMIT clauses, so we bind parameters manually
foreach
(
array_values
(
$params
)
as
$i
=>
$param
)
{
$dataType
=
filter_var
(
$param
,
FILTER_VALIDATE_INT
)
!==
false
?
PDO
::
PARAM_INT
:
PDO
::
PARAM_STR
;
$stmt
->
bindParam
(
$i
+
1
,
$param
,
$dataType
);
}
for
(
$attempt
=
0
;
$attempt
<
100
;
$attempt
++
)
{
for
(
$attempt
=
0
;
$attempt
<
100
;
$attempt
++
)
{
$success
=
$stmt
->
execute
(
$params
);
$success
=
$stmt
->
execute
();
if
(
$success
===
true
||
$stmt
->
errorCode
()
!==
'1213'
)
{
if
(
$success
===
true
||
$stmt
->
errorCode
()
!==
'1213'
)
{
break
;
break
;
...
...
qa-src/Database/DbResult.php
View file @
b8d37584
...
@@ -32,12 +32,12 @@ class DbResult
...
@@ -32,12 +32,12 @@ class DbResult
}
}
/**
/**
* Return the first row from the results as an array of [column name] =>
[column value]
.
* Return the first row from the results as an array of [column name] =>
'column value'
.
* @return array|null
* @return array|null
*/
*/
public
function
fetchNextAssoc
()
public
function
fetchNextAssoc
()
{
{
$data
=
$this
->
stmt
->
fetch
();
$data
=
$this
->
stmt
->
fetch
(
PDO
::
FETCH_ASSOC
);
return
$data
===
false
?
null
:
$data
;
return
$data
===
false
?
null
:
$data
;
}
}
...
...
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