Professional Information Technology-Programming Book part 84

Tham khảo tài liệu 'professional information technology-programming book part 84', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Debugging SQL When a PHP call to the MySQL interface encounters a database error the warnings displayed are not always as helpful as you might hope. In the following sections you will find out how to make the most of MySQL s error reporting to debug errors at the database level. SQL Errors When there is an error in a SQL statement it is not reported right away. You should check the return value from mysql_query to determine whether there was a problemit is NULL if the query has failed for any reason. This applies to DDL and DML statements as well as to SELECT queries. The following example tries to perform an invalid SQL statement the table name is missing from the DELETE command sql DELETE FROM res mysql_query sql db if res echo There was an SQL error exit If you want to find out why a call to mysql_query failed you must use the mysql_error and mysql_errno functions to retrieve the underlying MySQL warning text and error code number. A link resource argument can be provided but is required only if you have two or more open MySQL connections in the script if res echo Error . mysql_errno . in SQL echo PRE sql PRE echo mysql_error exit Debugging SQL When you re debugging SQL it is useful to see the query that was attempted alongside the error message particularly if your query uses variable substitutions. This is easy to do if the query is stored in a variablesuch as sql used throughout this lessonrather than given directly as an argument to mysql query. If you do not trap SQL errors in script PHP will continue to execute until an attempt is made to use the failed result resource. You will see an error message similar to the following if for instance mysql_result is called with an invalid res value Warning mysql_result supplied argument is not a valid MySQL result resource in home chris on line 8 This error does not give any indication of what the problem was or even when in the script it occurred. The line number given is the line of the mysql_result call

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
5    75    1    02-07-2024
20    87    2    02-07-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.