SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: MySql problems

  1. #1
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    MySql problems

    Hi all,

    We have a website for selling books, developed with HTML, PHP y MySQL.
    In a certail page, where the website interacts with the database, in a few cases only part of the page is loaded, so the customer is not able to complete the purchase.

    An example of the PHP code is:
    $insert_quotation = "INSERT INTO `Quotations_DSStgo`(`QuotationID`, `Date`, `Status`, `CustomerID`, `BookID`, `ClassID`) VALUES ('NULL','NULL', '0', '$CustomerID','$Book_ID', '$ClassID')";
    mysql_query($insert_quotation, $db_handle) or die(mysql_error());

    My question is: in case of an error, how can I keep the code but send the error message information to a log in order I am able to see what is happening?
    I think the problem is in certain cases an error happens and "die", but I do not have information about the error, so I am unable to solve it.

    Thanks a lot!!!!
    Sir_Arcturus

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    The first question is, is it a PHP error or a MySQL error?
    I would guess PHP, as whatever you are attempting to do in the PHP code is causing the page to choke.

    Both PHP and MySQL have error logs, but whether you have access to them is another question.
    What is your hosting set up?

    What do you see listed under "error_log" when you do phpinfo()?

  3. #3
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks a lot.
    Unfortunately when I run this command I get:
    phpinfo() has been disabled for security reasons

    Sorry for that ...

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    No drama.
    Are you on shared hosting?

  5. #5
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes, I am ...

  6. #6
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    While shared hosting is adequate for a lot of purposes, one annoyance is that they don't normally provide access to Apache error logs.
    So, what you can then do, is simply create your own error logs for certain pages:

    PHP Code:
    <?php 
    error_reporting
    (0); // Turns off all error reporting.

    function userErrorHandler($errno$errmsg$filename$linenum$vars)
    {
        
    $dt date('Y-m-d H:i:s (T)');

        
    // define an assoc array of error string
        
    $errortype = array (
                    
    E_ERROR => 'Error',
                    
    E_WARNING => 'Warning',
                    
    E_PARSE => 'Parsing Error',
                    
    E_NOTICE => 'Notice',
                    
    E_CORE_ERROR => 'Core Error',
                    
    E_CORE_WARNING => 'Core Warning',
                    
    E_COMPILE_ERROR => 'Compile Error',
                    
    E_COMPILE_WARNING => 'Compile Warning',
                    
    E_USER_ERROR => 'User Error',
                    
    E_USER_WARNING => 'User Warning',
                    
    E_USER_NOTICE => 'User Notice',
                    
    E_STRICT => 'Runtime Notice'
                    
    );
                                    
        
    // set of errors for which a var trace will be saved.
        
    $user_errors = array(E_USER_ERRORE_USER_WARNINGE_USER_NOTICE);

        
    $err "<errorentry>\n";
        
    $err .= "\t<datetime>" .$dt"</datetime>\n";
        
    $err .= "\t<errornum>" .$errno"</errornum>\n";
        
    $err .= "\t<errortype>" .$errortype[$errno]. "</errortype>\n";
        
    $err .= "\t<errormsg>" .$errmsg"</errormsg>\n";
        
    $err .= "\t<scriptname>" .$filename"</scriptname>\n";
        
    $err .= "\t<scriptlinenum>" .$linenum"</scriptlinenum>\n";

        if (
    in_array($errno$user_errors)) {
            
    $err .= "\t<vartrace>" .wddx_serialize_value($vars'Variables'). "</vartrace>\n";
        }
        
    $err .= "</errorentry>\n\n";

        
    // save to the error log file, and e-mail me if there is a critical user error.
        
    error_log($err3'error_log.log');
            
        if (
    $errno == E_USER_ERROR) {
            
    mail('you@address.com''Critical User Error'$err);
        }
    }
    $new_error_handler set_error_handler('userErrorHandler');
    Save this code into a PHP file, upload it to your server and then include it into the page that is causing you problems (using the include() method).
    What it'll do is to log any errors the PHP script creates into a file called error_log.log in the same directory.
    You can also set your mail at the bottom of the script, so that it mails you in the event of a critical user error (or any error if you so desire).
    I can't claim credit for the code. I found it here: http://www.hotscripts.com/blog/php-e...-file-archive/

    Not sure if this will help you solve the problem, but should bring you a step forward at least.

  7. #7
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot, I have much more info now.

    Based on that, I created a new post. I'd appreciate if you can take a look:
    http://www.sitepoint.com/forums/show...03#post5269503

    Thanks again!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •