Phptrycatch: catch an exception and throw an exception

Source: Internet
Author: User
Tags php try catch
: This article mainly introduces phptrycatch: catch exceptions and throw exceptions. For more information about PHP tutorials, see. Php try catch: catch exceptions and throw exceptions:

/*** Constructor: automatically load and connect to the database * @ param $ database $ key * @ return */private function _ construct ($ database = array (), $ key) {try {$ this-> server = $ database ['DB _ host']; $ this-> username = $ database ['DB _ user']; $ this-> password = $ database ['DB _ pwd']; $ this-> database_name = $ database ['DB _ name']; $ this-> database_type = $ database ['DB _ type']; $ this-> database_port = $ database ['DB _ port']; if ($ this-> database_type = 'mysql') {$ this-> pdo = new PDO ($ this-> database_type. ': host = '. $ this-> server. '; port = '. $ this-> database_port. '; dbname = '. $ this-> database_name, $ this-> username, $ this-> password, array (PDO: ATTR_TIMEOUT => self: TIME_OUT ));} else {$ this-> pdo = new PDO ("dblib: host = $ this-> server: $ this-> database_port; dbname = $ this-> database_name ", "$ this-> username", "$ this-> password") ;}$ this-> pdo-> exec ('set NAMES \''. $ this-> charset. '\ ''); self: $ pdo_ref [$ key] = & $ this-> pdo;} catch (PDOException $ e) {echo $ e-> getMessage ();}}

The above introduces php try catch: catch exceptions and throw exceptions, including related content. For more information, see PHP Chinese website (www.php1.cn )!

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.