PDO offers three different error-handling modes

Source: Internet
Author: User

Pdo::errmode_silent

This is the default mode. PDO will simply set the error code and use the Pdo::errorcode () and Pdo::errorinfo () methods to examine the statements and database objects. If the error is caused by a call to the statement object, you can call the Pdostatement::errorcode () or Pdostatement::errorinfo () method of that object. If the error occurs because of a call to a database object, you can invoke both methods on the database object.

Pdo::errmode_warning

In addition to setting the error code, PDO will emit a traditional e_warning message. This setting is useful during debugging/testing if you just want to see what's going on and don't interrupt the application's process.

Pdo::errmode_exception (Note: It will throw an exception inside itself, end-of-page)

In addition to setting the error code, PDO throws a Pdoexception exception class and sets its properties to reflect the error code and error message. This setting is also useful during debugging because it effectively magnifies the points in the script that produce the error, so that you can quickly point out potential areas of the code that are problematic (remember: If the exception causes the script to terminate, the transaction is automatically rolled back).

Exception mode Another very useful is that, compared to traditional PHP style warnings, you can build your own error handling more clearly, and the exception pattern requires less code/nesting than silent mode and explicitly checking the return value of each database call.

PDO offers three different error-handling modes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.