Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qfq
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
typo3
qfq
Commits
149129d2
Commit
149129d2
authored
9 years ago
by
Carsten Rose
Browse files
Options
Downloads
Patches
Plain Diff
Database.php: wrote some phpdoc. renamed function fakeBindParam()
parent
d6cc4a77
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
extension/qfq/qfq/Database.php
+29
-61
29 additions, 61 deletions
extension/qfq/qfq/Database.php
with
29 additions
and
61 deletions
extension/qfq/qfq/Database.php
+
29
−
61
View file @
149129d2
...
...
@@ -181,12 +181,15 @@ class Database {
}
/**
* Fires query $sql and fetches result als assoc array.
* $mode
* ROW_REGULAR return result set as assoc array. No check about number of rows.
* ROW_IMPLODE_ALL return result set as one string: implode all rows and columns. No check about number of rows.
* ROW_EXACT_1 return result set as assoc array. It has to be exact one row selected. If not: throw Exception,
* ROW_EMPTY_IS_OK return result set as assoc array. It has to be 0 or one row selected. If not: throw Exception,
* Fires query $sql and fetches result als assoc array (all modes but ROW_KEYS) or as num array (mode: ROW_EKYS). Throws exception.
* $mode
* ROW_REGULAR: Return 2-dimensional assoc array. Every query row is one array row.
* ROW_IMPLODE_ALL: Return string. All cells of all rows imploded to one string.
* ROW_EXPECT_0: Return empty string if there is now record row, Else an exception.
* ROW_EXPECT_1: Return 1-dimensional assoc array if there are exact one row. Else an exception.
* ROW_EXPECT_0_1: Return empty string if there is no row. Return 1- dimensional assoc array if there is one row. Else an exception.
* ROW_EXPECT_GE_1: Like 'ROW_REGULAR'. Throws an exception if there is an empty resultset.
* ROW_KEYS: Return 2-dimensional num(!) array. Every query row is one array row. In $keys are the column names.
*
* @param $sql
* @param string $mode
...
...
@@ -280,37 +283,30 @@ class Database {
/**
* Execute a prepared SQL statement like SELECT, INSERT, UPDATE, DELETE, SHOW, ...
*
*
The result of the query can be retrieved by using one
o
f
the
fetch methods.
*
Returns the number of selected rows (SELECT, SHOW, ..)
o
r
the
affected rows (UPDATE) or the last insert id (INSERT)
*
* @param string $sql SQL statement with prepared statement variable.
* @param array $parameterArray parameter array for prepared statement execution.
* @return mixed
* @return int|mixed
* @throws \qfq\CodeException
* @throws \qfq\DbException
* @throws \qfq\UserException
*/
private
function
prepareExecute
(
$sql
,
array
$parameterArray
=
array
())
{
$result
=
null
;
$result
=
0
;
$this
->
store
->
setVar
(
SYSTEM_SQL_FINAL
,
$sql
,
STORE_SYSTEM
);
$this
->
store
->
setVar
(
SYSTEM_SQL_PARAM_ARRAY
,
$parameterArray
,
STORE_SYSTEM
);
// Logfile
$this
->
dbLog
(
$sql
,
$parameterArray
);
// Prepared Statement?
// if (count($parameterArray) === 0) {
// if (false === ($result = $this->mysqli->query($sql))) {
// throw new DbException('[ mysqli: ' . $this->mysqli->errno . ' ] ' . $this->mysqli->error, ERROR_DB_QUERY);
// }
//
// } else {
if
(
false
===
(
$this
->
mysqli_stmt
=
$this
->
mysqli
->
prepare
(
$sql
)))
{
throw
new
DbException
(
'[ mysqli: '
.
$this
->
mysqli
->
errno
.
' ] '
.
$this
->
mysqli
->
error
,
ERROR_DB_PREPARE
);
}
if
(
count
(
$parameterArray
)
>
0
)
{
if
(
false
===
$this
->
fakeCallUserFunc
(
$parameterArray
))
{
if
(
false
===
$this
->
prepareBindParam
(
$parameterArray
))
{
throw
new
DbException
(
'[ mysqli: '
.
$this
->
mysqli_stmt
->
errno
.
' ] '
.
$this
->
mysqli_stmt
->
error
,
ERROR_DB_BIND
);
}
}
...
...
@@ -318,7 +314,6 @@ class Database {
if
(
false
===
$this
->
mysqli_stmt
->
execute
())
{
throw
new
DbException
(
'[ mysqli: '
.
$this
->
mysqli_stmt
->
errno
.
' ] '
.
$this
->
mysqli_stmt
->
error
,
ERROR_DB_EXECUTE
);
}
// }
$msg
=
''
;
$count
=
0
;
...
...
@@ -390,19 +385,7 @@ class Database {
/**
* @param $arr
*/
private
function
fakeCallUserFunc
(
$arr
)
{
// $type = '';
//
// foreach ($arr as $value) {
// if (is_int($value)) {
// $type .= 'i';
// } elseif (is_double($value)) {
// $type .= 'd';
// } else {
// $type .= 's';
// }
// }
private
function
prepareBindParam
(
$arr
)
{
$bindParam
=
new
BindParam
();
...
...
@@ -410,45 +393,27 @@ class Database {
$bindParam
->
add
(
$arr
[
$ii
]);
}
call_user_func_array
([
$this
->
mysqli_stmt
,
'bind_param'
],
$bindParam
->
get
());
// switch (count($arr)) {
// case 0:
// break;
// case 1:
// $this->mysqli_stmt->bind_param($type, $arr[0]);
// break;
// case 2:
// $this->mysqli_stmt->bind_param($type, $arr[0], $arr[1]);
// break;
// case 3:
// $this->mysqli_stmt->bind_param($type, $arr[0], $arr[1], $arr[2]);
// break;
// case 4:
// $this->mysqli_stmt->bind_param($type, $arr[0], $arr[1], $arr[2], $arr[3]);
// break;
// case 5:
// $this->mysqli_stmt->bind_param($type, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4]);
// break;
// case 6:
// $this->mysqli_stmt->bind_param($type, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5]);
// break;
// case 7:
// $this->mysqli_stmt->bind_param($type, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6]);
// break;
// default:
// throw new DbException('Oops, too many parameter in prepared statement.', 0);
// }
}
/**
* Fetch all rows of the result as associative array.
*
* @return mixed false in case of error.
* mode:
* ROW_IMPLODE_ALL: Return string. All cells of all rows imploded to one string.
* ROW_KEYS: Retrun num array with column names in $keys
* default: Return 2-dimensional assoc array
*
* @param string $mode
* @param array $keys
* @return array|bool|mixed|string false in case of error.
* Empty string is returned if the query didn't yield any rows.
* All rows as Multi Assoc array if $mode!=IMPLODE_ALL.
* All rows and all columns imploded to one string if $mode=IMPLODE_ALL
*
*/
/**
* @return array|bool|mixed|string
*/
private
function
fetchAll
(
$mode
=
''
,
&
$keys
=
array
())
{
if
(
$this
->
mysqli_result
==
null
||
$this
->
mysqli_result
==
false
)
{
return
false
;
...
...
@@ -482,6 +447,8 @@ class Database {
}
/**
* Wrapper for sql(), to simplyfy access.
*
* @param $sql
* @param array $keys
* @return array|bool
...
...
@@ -498,6 +465,7 @@ class Database {
* @return string
*/
public
function
getLastInsertId
()
{
// Do not try to use $this->mysqli->lastInsertId - this is not valid at any given time.
return
$this
->
mysqli
->
insert_id
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment