Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
0f618162
Commit
0f618162
authored
12 years ago
by
Frank Karlitschek
Browse files
Options
Downloads
Patches
Plain Diff
A new function to create nice error page. And use it for fatal db errors
parent
fb5d0db0
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/db.php
+8
-40
8 additions, 40 deletions
lib/db.php
lib/template.php
+15
-0
15 additions, 0 deletions
lib/template.php
with
23 additions
and
40 deletions
lib/db.php
+
8
−
40
View file @
0f618162
...
...
@@ -168,11 +168,7 @@ class OC_DB {
try
{
self
::
$PDO
=
new
PDO
(
$dsn
,
$user
,
$pass
,
$opts
);
}
catch
(
PDOException
$e
)
{
$error
[
'error'
]
=
'<b>can not connect to database, using '
.
$type
.
'. ('
.
$e
->
getMessage
()
.
')</center>'
;
$error
[
'hint'
]
=
''
;
$errors
[]
=
$error
;
OC_Template
::
printGuestPage
(
""
,
"error"
,
array
(
"errors"
=>
$errors
));
die
();
OC_Template
::
printErrorPage
(
'<b>can not connect to database, using '
.
$type
.
'. ('
.
$e
->
getMessage
()
.
')'
);
}
// We always, really always want associative arrays
self
::
$PDO
->
setAttribute
(
PDO
::
ATTR_DEFAULT_FETCH_MODE
,
PDO
::
FETCH_ASSOC
);
...
...
@@ -268,11 +264,7 @@ class OC_DB {
if
(
PEAR
::
isError
(
self
::
$MDB2
))
{
OC_Log
::
write
(
'core'
,
self
::
$MDB2
->
getUserInfo
(),
OC_Log
::
FATAL
);
OC_Log
::
write
(
'core'
,
self
::
$MDB2
->
getMessage
(),
OC_Log
::
FATAL
);
$error
[
'error'
]
=
'<b>can not connect to database, using '
.
$type
.
'. ('
.
self
::
$MDB2
->
getUserInfo
()
.
')</center>'
;
$error
[
'hint'
]
=
''
;
$errors
[]
=
$error
;
OC_Template
::
printGuestPage
(
""
,
"error"
,
array
(
"errors"
=>
$errors
));
die
();
OC_Template
::
printErrorPage
(
'can not connect to database, using '
.
$type
.
'. ('
.
self
::
$MDB2
->
getUserInfo
()
.
')'
);
}
// We always, really always want associative arrays
...
...
@@ -332,11 +324,7 @@ class OC_DB {
$entry
.
=
'Offending command was: '
.
htmlentities
(
$query
)
.
'<br />'
;
OC_Log
::
write
(
'core'
,
$entry
,
OC_Log
::
FATAL
);
error_log
(
'DB error: '
.
$entry
);
$error
[
'error'
]
=
$entry
;
$error
[
'hint'
]
=
''
;
$errors
[]
=
$error
;
OC_Template
::
printGuestPage
(
""
,
"error"
,
array
(
"errors"
=>
$errors
));
die
();
OC_Template
::
printErrorPage
(
$entry
);
}
}
else
{
try
{
...
...
@@ -346,11 +334,7 @@ class OC_DB {
$entry
.
=
'Offending command was: '
.
htmlentities
(
$query
)
.
'<br />'
;
OC_Log
::
write
(
'core'
,
$entry
,
OC_Log
::
FATAL
);
error_log
(
'DB error: '
.
$entry
);
$error
[
'error'
]
=
$entry
;
$error
[
'hint'
]
=
''
;
$errors
[]
=
$error
;
OC_Template
::
printGuestPage
(
""
,
"error"
,
array
(
"errors"
=>
$errors
));
die
();
OC_Template
::
printErrorPage
(
$entry
);
}
$result
=
new
PDOStatementWrapper
(
$result
);
}
...
...
@@ -463,11 +447,7 @@ class OC_DB {
// Die in case something went wrong
if
(
$definition
instanceof
MDB2_Schema_Error
)
{
$error
[
'error'
]
=
$definition
->
getMessage
()
.
': '
.
$definition
->
getUserInfo
();
$error
[
'hint'
]
=
''
;
$errors
[]
=
$error
;
OC_Template
::
printGuestPage
(
""
,
"error"
,
array
(
"errors"
=>
$errors
));
die
();
OC_Template
::
printErrorPage
(
$definition
->
getMessage
()
.
': '
.
$definition
->
getUserInfo
()
);
}
if
(
OC_Config
::
getValue
(
'dbtype'
,
'sqlite'
)
===
'oci'
)
{
unset
(
$definition
[
'charset'
]);
//or MDB2 tries SHUTDOWN IMMEDIATE
...
...
@@ -479,11 +459,7 @@ class OC_DB {
// Die in case something went wrong
if
(
$ret
instanceof
MDB2_Error
)
{
$error
[
'error'
]
=
self
::
$MDB2
->
getDebugOutput
()
.
' '
.
$ret
->
getMessage
()
.
': '
.
$ret
->
getUserInfo
();
$error
[
'hint'
]
=
''
;
$errors
[]
=
$error
;
OC_Template
::
printGuestPage
(
""
,
"error"
,
array
(
"errors"
=>
$errors
));
die
();
OC_Template
::
printErrorPage
(
self
::
$MDB2
->
getDebugOutput
()
.
' '
.
$ret
->
getMessage
()
.
': '
.
$ret
->
getUserInfo
()
);
}
return
true
;
...
...
@@ -596,11 +572,7 @@ class OC_DB {
$entry
.
=
'Offending command was: '
.
$query
.
'<br />'
;
OC_Log
::
write
(
'core'
,
$entry
,
OC_Log
::
FATAL
);
error_log
(
'DB error: '
.
$entry
);
$error
[
'error'
]
=
$entry
;
$error
[
'hint'
]
=
''
;
$errors
[]
=
$error
;
OC_Template
::
printGuestPage
(
""
,
"error"
,
array
(
"errors"
=>
$errors
));
die
();
OC_Template
::
printErrorPage
(
$entry
);
}
if
(
$result
->
numRows
()
==
0
)
{
...
...
@@ -632,11 +604,7 @@ class OC_DB {
$entry
.
=
'Offending command was: '
.
$query
.
'<br />'
;
OC_Log
::
write
(
'core'
,
$entry
,
OC_Log
::
FATAL
);
error_log
(
'DB error: '
.
$entry
);
$error
[
'error'
]
=
$entry
;
$error
[
'hint'
]
=
''
;
$errors
[]
=
$error
;
OC_Template
::
printGuestPage
(
""
,
"error"
,
array
(
"errors"
=>
$errors
));
die
();
OC_Template
::
printErrorPage
(
$entry
);
}
return
$result
->
execute
();
...
...
This diff is collapsed.
Click to expand it.
lib/template.php
+
15
−
0
View file @
0f618162
...
...
@@ -496,4 +496,19 @@ class OC_Template{
}
return
$content
->
printPage
();
}
/**
* @brief Print a fatal error page and terminates the script
* @param string $error The error message to show
* @param string $hint An option hint message
*/
public
static
function
printErrorPage
(
$error
,
$hint
=
''
)
{
$error
[
'error'
]
=
$error
;
$error
[
'hint'
]
=
$hint
;
$errors
[]
=
$error
;
OC_Template
::
printGuestPage
(
""
,
"error"
,
array
(
"errors"
=>
$errors
));
die
();
}
}
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