About PDO--Error and error handling

Source: Internet
Author: User

PDO Introduction-Error and error handlingTags: Database exception script Phpup2008-09-28 19:421623 People readComments (0)ReportCategory:PHP (Ten)

For your application development, PDO offers different error handling strategies in 3.

    1. Pdo::errmode_silent

      This is the default mode used. PDO will set simple error codes on the statement and database objects, and you can use the pdo->errorcode () and Pdo->errorinfo () methods to check for errors If the error is caused by a call to the statement object, you can use Pdostatement->errorcode () or pdostatement->errorinfo () on that object method to obtain an error message. If the error is caused by a call to the database object, you should call the two methods on the database object.

    2. Pdo::errmode_warning

      PDO will emit a traditional e_warning message as an addition to the setup error code. This setting is useful in debugging and debug, if you just want to see what's going on and don't want to interrupt the process.

    3. Pdo::errmode_exception

      As an attachment that sets the error code, PDO throws an Pdoexception exception and sets its properties to reflect the error code and error message. This setting is useful in addition to errors, because he will effectively "zoom in (Blow up)" The error point in the script, very quickly point to a possible error area in your code. (Remember: If the exception causes the script to break, the transaction is automatically rolled back.) )

      The exception mode is also useful because you can use a much clearer structure-handling error than the traditional PHP-style error-handling structure, using less code and nesting than quiet mode, and more explicitly checking the return value of each database access.

      For more information about exceptions in PHP, see the Exceptions section

PDO uses the SQL-92 SQLSTATE-based error code string, and the specific PDO driver should correspond its own code name to the appropriate SQLSTATE code. The Pdo->errorcode () method returns only a single SQLState designator. If you need more targeted information about a bug, PDO also provides a Pdo->errorinfo () method that can return a SQLSTATE code that contains the A specific database-driven error code and a specific database-driven error description string.

Top
0
Step
0
  • Previous Article PDO Introduction The three classes and their methods in--pdo
  • Next Article Introduction to PDO--transaction processing and automatic submission
My Kind of articlePHP (Ten)

About PDO--Error and error handling

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.