• Mysql fatal error

    Закрыть ... [X]

    When creating large applications it's quite handy to create a custom function for handling queries. Just include this function in every script. And use db_query(in this example) instead of mysql_query.

    This example prompts an error in debugmode (variable $b_debugmode ). An e-mail with the error will be sent to the site operator otherwise.

    The script writes a log file in directory ( in this case /log error ) as well.

    The system is vulnerable when database/query information is prompted to visitors. So be sure to hide this information for visitors anytime.


    Lennart Poot

    $b_debugmode = 1; // 0 || 1

    $system_operator_mail = '';
    $system_from_mail = '';

    function db_query( $query ){
      global $b_debugmode;
      // Perform Query
      $result = mysql_query($query);

      // Check result
      // This shows the actual query sent to MySQL, and the error. Useful for debugging.
      if (!$result) {
          $message  = '<b>Invalid query:</b><br>'. mysql_error(). '<br><br>';
          $message.= '<b>Whole query:</b><br>'. $query. '<br><br>';

        raise_error('db_query_error: '. $message);
      return $result;

      function raise_error( $message ){
        global $system_operator_mail, $system_from_mail;

        "Env:       ". $_SERVER['SERVER_NAME']. "\r\n".
        "timestamp: ". Date('m/d/Y H:i:s'). "\r\n".
        "script:    ". $_SERVER['PHP_SELF']. "\r\n".
        "error:     ". $message."\r\n\r\n";

        // open a log file and write error
        $fhandle mysql fatal error = fopen( '/logs/errors'.date('Ymd').'.txt', 'a' );
          fwrite( $fhandle, $serror );
          fclose(( $fhandle ));
        // e-mail error to system operator
          mail($system_operator_mail, 'error: '.$message, $serror, 'From: '. $system_from_mail );


    Источник: http://php.net/manual/kr/function.mysql-error.php

    Рекомендуем посмотреть ещё:

    Fatal error: Can't open and lock privilege tables: Table Что приготовить на Новый год 2018 Обезьяны

    Mysql fatal error Mysql fatal error Mysql fatal error Mysql fatal error Mysql fatal error Mysql fatal error Mysql fatal error