Debugging a PHP application if often more difficult than debugging an application in some other programming language. There are two reasons for this.
[ PHP developers have many good IDEs to choose from. See the InfoWorld Test Center's comparison of ActiveState Komodo, CodeLobster, Eclipse PDT, phpDesigner, NetBeans, NuSphere PhpED, PHPEdit, and Zend Studio. ]
Second, a PHP Web application does not have a continuous, linear flow of execution. Its execution is a series of HTTP request/response transactions. Each transaction is independent of all other preceding and following request/response pairs. While it is true that, from a user's perspective, the application gives the impression of a monolithic unity, that effect is maintained by artifacts such as cookies or hidden fields. The presence of such artifacts does not inform the debugger of a transaction-spanning Web session.
The upshot is that, if you start a debug session on file X.PHP, when X.PHP sends its HTTP response, that PHP code is completed. A subsequent HTTP request in the same user session might trigger the execution of file Y.PHP. Consequently, a single user session effectively passes through multiple debug sessions.
Developers can deal with the "multiple languages" issue using a collection of debug tools, each outfitted for its particular domain. A PHP debugger "extension" handles debugging PHP code. One of the most popular extensions is the Xdebug, a free PHP debugger, which is installed as a dynamic link library on Windows or as a shared library on Linux. Xdebug can be used with virtually any Web server, because it is attached to the PHP runtime and not the Web server.
Xdebug provides all the basic debugging capabilities: breakpoints, stack traces, variable watches, and so on. It also makes special functions available to the executing program. For example, you can display the amount of memory a PHP application is using by calling Xdebug's xdebug_memory_usage() function. Finally, Xdebug can be configured to track an HTTP session. Appending an XDEBUG_SESSION_START parameter to the URL of an HTTP request will cause Xdebug to emit a cookie to the browser, thus enabling a single debug session to span multiple HTTP transactions.
Debugging SQL is different from debugging a procedural language. Testing the correctness of a query is often done simply by building and executing the query in ad hoc fashion -- that is, typing the query into an SQL management console and verifying the results. Many PHP IDEs provide database tools for this very reason. For example, the Database Development Toolkit in Eclipse (and Zend Studio) includes ad hoc query execution, as well as execution statistics. With the proper plug-in (dependent on the database engine), you can also display query plan information.