Autor Beitrag
Supernova
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 108

WinXP
D7 Prof
BeitragVerfasst: Mo 03.04.06 20:07 
Hallo,

ich versuche eine Fehlerausgabe für MySql zu machen, damit diese Standard Meldungen nicht kommen ... :wink:

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
<?php
  
  $db_username = "";  
  $db_password = "";  
  
  $db_name = "";  
  $db_host = "";  
  
  $db_link = @mysql_connect($db_host, $db_username, $db_password);  
  
  if($db_link)
  {
    if(mysql_select_db($db_name, $db_link))
    {
    
    }
    else
    {
      echo <<< HTML
      
      <html>
        <head>
          <title>
            Fehler: Die Datenbank {$db_name} konnte nicht ausgew&aum;hlt werden.
          </title>
        </head>
        <body>
          <font style="color: red; font-size: 11px; font-family: verdana, arial, helvetica, sans-serif; text-align: center; margin-top: 100px;">
            <center>
              Die Datenbank <b>{$db_name}</b> konnte nicht ausgewählt werden, bitte benachrichtige den Webmaster, und versuche es später erneut.
              <br>
              <br>
              <font style="color: black;">
                Du wirst in einem Augenblick zu dem "Error-Reporing" - Forumlar geleitet ...
              </font>
            </center>
          </font>
        </body>
      </html>
      
      HTML;
    }
  }
  else
  {
    echo <<< HTML
    
    <html>
        <head>
          <title>
            Fehler: Die Datenbank {$db_name} konnte nicht ausgew&aum;hlt werden.
          </title>
        </head>
        <body>
          <font style="color: red; font-size: 11px; font-family: verdana, arial, helvetica, sans-serif; text-align: center; margin-top: 100px;">
            <center>
              Die Datenbank <b>{$db_name}</b> konnte nicht ausgewählt werden, bitte benachrichtige den Webmaster, und versuche es später erneut.
              <br>
              <br>
              <font style="color: black;">
                Du wirst in einem Augenblick zu dem "Error-Reporing" - Forumlar geleitet ...
              </font>
            </center>
          </font>
        </body>
      </html>
    
    HTML;
  }
   
?>


Allerdings wie Sieht es dann mit der Performance aus, Ladezeit etc. , denn so etwas sehe ich in keine mysql_connect.php

Grüße,
Supernova

Moderiert von user profile iconKlabautermann: Quote- durch Code-Tags ersetzt

_________________
Input - Output => Ganz Kaputt
*** MFG Supernova ***
blackbirdXXX

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: Mo 03.04.06 20:21 
Schreib dir lieber ein Exception/Error System und wirf einen Fehler. Das geht mit Umwegen sogar unter php4.

_________________
Klein, schwarz und ärgert Techniker? Jumper!
Supernova Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 108

WinXP
D7 Prof
BeitragVerfasst: Mo 03.04.06 20:26 
Kannst du mir da vllt. ein Beispiel geben?

Wäre super nett ...

Grüße,
Supernova

_________________
Input - Output => Ganz Kaputt
*** MFG Supernova ***
blackbirdXXX

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: Di 04.04.06 04:48 
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
<?php
/**
 * Main Application
 */

error_reporting(E_ALL);

/**
 * Small Exception Handler for nice
 * formatted output
 */
function exception_handler($exc) {
    if (method_exists($exc, 'getFormattedMessage')) {
        echo $exc->getFormattedMessage();
    }
    else {
        echo '<h1>Error ' . $exc->getCode() . '</h1>';
        echo '<p>' . htmlspecialchars($exc->getMessage()) . '</p>';
        echo '<pre>file: ' . $exc->getFile();
        echo ', line ' . $exc->getLine() . '</pre>';
        $traceback = $exc->getTrace();
        if (count($traceback)) {
            echo '<h2>Traceback</h2>';
            foreach ($traceback as $tb) {
                echo '<pre>file: ' . $tb['file'] . "\n";
                echo 'line: ' . $tb['line'] . "\n";
                echo 'function: ' . $tb['function'];
                if (count($tb['args'])) {
                    echo "\nargs: \n   ";
                    echo htmlspecialchars(implode("\n   ", $tb['args']));
                }
                echo '</pre>';
            }
        }
    }
}
set_exception_handler('exception_handler');

/**
 * Example Exceptions
 */
class ImproperConfiguration extends Exception
{
    public function __construct($msg=false) {
        if ($msg === false) {
            $msg = 'unknown reason';
        }
        parent::__construct('Improper Configuration: ' . $msg, 310);
    }

    public function getFormattedMessage() {
        return '<h1>Improper Configuration</h1>'. "\n".
        '<p>' . $this->getMessage() . '</p>';
    }
}

class PageNotFound extends Exception
{
    private $app;

    public function __construct($app) {
        $this->app = $app;
        parent::__construct('Page Not Found', 404);
    }

    public function getFormattedMessage() {
        return '<h1>Page Not Found</h1>'
        . '<p>The requested path ' . $this->app->request
        . ' was not found on the server.</p>';
    }
}

/**
 * Application
 */
class Application {
    public $request;
    public $params;
    public $form;
    
    public function __construct() {
        if (isset($_SERVER['PATH_INFO'])) {
            $this->request = $_SERVER['PATH_INFO'];
        }
        else {
            $this->request = '/';
        }
        $this->params = Array();
        $this->form = Array();
        $quotes = get_magic_quotes_gpc();
        foreach ($_GET as $key => $value) {
            if ($quotes) {
                $this->params[$key] = $value;
            }
            else {
                $this->params[$key] = stripslashes($value);
            }
        }
        foreach ($_POST as $key => $value) {
            if ($quotes) {
                $this->form[$key] = $value;
            }
            else {
                $this->form[$key] = stripslashes($value);
            }
        }
    }

    public function execute() {
        if ($this->request == '/') {
            throw new ImproperConfiguration('argh. something went wrong in the config.');
        }
        else {
            throw new PageNotFound($this);
        }
    }
}

function on_request() {
    $app = new Application();
    $app->execute();
}
on_request();
?>


Ich hoffe das hilft dir.

Nochwas zur Erklärung. Einen Teil davon hab ich aus alten Code Schnippseln von mir genommen und entschlackt. Wenn du einen Fehler wirfst schaut er zuerst, obs ein getFormattedMessage gibt, dann ruft er das auf und gibts zurück, ansonsten präsentiert er dir einen vereinfachten Traceback. Die Funktion on_request ist eigentlich sinnlos, aber eaccellerator hat damit einen Freude :)

Das Original von mir hatte keine Funktion getFormattedMessage, sondern ein getExceptionContext, dass ein Array für smarty zurückgegeben hat, das wurde dann direkt in ein Template gerendert.

_________________
Klein, schwarz und ärgert Techniker? Jumper!