How can I change the mysql-php pdo to another database if the connection fails?

Source: Internet
Author: User
If the connection to database A fails, how can I connect to database B? What should I do without the trycatch method? NewPDO directly throws an exception if it fails and cannot proceed to the next step. Please help me !!!!!!!!!!!!! {Code...} How can I connect to database B if the connection to database A fails?
If try catch is not required, what should I do? If a failure occurs, new PDO directly throws an exception and cannot proceed to the next step. Please help me !!!!!!!!!!!!!


  setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);} catch (PDOException $e) {    echo 'Connection failed: ' . $e->getMessage();}?>

Reply content:

How can I connect to database B if database A fails?
If try catch is not required, what should I do? If a failure occurs, new PDO directly throws an exception and cannot proceed to the next step. Please help me !!!!!!!!!!!!!


  setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);} catch (PDOException $e) {    echo 'Connection failed: ' . $e->getMessage();}?>

Connect to catch and store exceptions in logs

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.