: 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 )!