debugging problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sejal17
    New Member
    • Dec 2007
    • 56

    debugging problem

    hello,
    Can anyone tell me how can i debug in php?Please write down the steps for it.
    Is there any configuration change with apache server?

    Thanks in advance.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Check this article out.

    Comment

    • coolsti
      Contributor
      • Mar 2008
      • 310

      #3
      Good article in that link.

      What I do is set up my php.ini so that I see error messages in the browser. This also gives the line number where the error occurred.

      Otherwise I debug just using a lot of echo statements placed where needed, to examine the values of certain variables at various points in the script. To debug a database query, I often echo out the query statement to the browser, and then copy and paste the query or parts of it directly to a mysql console window.

      What is useful is a sort of stack trace at the point of where an error occurs, but I have not used this yet. Would be handy if you get errors in very common functions that are called from various places in the script.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by coolsti
        .... To debug a database query, I often echo out the query statement to the browser, and then copy and paste the query or parts of it directly to a mysql console window.

        What is useful is a sort of stack trace at the point of where an error occurs, but I have not used this yet. Would be handy if you get errors in very common functions that are called from various places in the script.
        For the database error you can print out the sql error itself e.g for mysql you can use the mysql_error function.

        Comment

        • nathj
          Recognized Expert Contributor
          • May 2007
          • 937

          #5
          The thing I find most annoying in PHP is the inability to step through your code as it executes. I come from a desktop development background originally and so am used to the functionality.

          However, when faced with a problem that required the ability to watch the code as it executed I simply developed a basic fle output object. What this does is create a text file on the server for you and then it writes to the file whatever you want.

          If you are trying to establish the value of some variables at run time then output them to the text file and see what it says afterwards.

          I have used this a few times and it's helped me track down logic errors and all sorts. Basically it's a great option if there are no syntax or semantic errors in the code but it still doesn't produce the desired results. Checking the variables as they change like this can really help you to understand what the code is doing.

          If you want me to post the object code and small article about it let me know and I'll do so.

          Cheers
          nathj

          Comment

          • coolsti
            Contributor
            • Mar 2008
            • 310

            #6
            Originally posted by r035198x
            For the database error you can print out the sql error itself e.g for mysql you can use the mysql_error function.
            Good point, I do this also.

            I was thinking more of debugging why a query is not giving me what I want it to give me, or is going too slowly, or had an obscure syntax error that I could not really see in the error report.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              I haven't used eclipse with PHP but doesn't it allow you to debug?

              Comment

              • Atli
                Recognized Expert Expert
                • Nov 2006
                • 5062

                #8
                Originally posted by r035198x
                I haven't used eclipse with PHP but doesn't it allow you to debug?
                Yea, I think it does.
                I've also been using Zend Studio for Eclipse, which does have a Debugger with breakpoints and everything.

                Comment

                • pbmods
                  Recognized Expert Expert
                  • Apr 2007
                  • 5821

                  #9
                  You can also write your own custom error handler.

                  I've written one that I really like (but it's not officially open source yet, so I can't post it here). It displays a source report (shows about 40 lines of code surrounding the line where the error occurred), a context report (all variables defined in that scope) and a backtrace report.

                  Here's a publicly-available one:

                  Comment

                  Working...