www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] Multiple PDO DB connections

  1. #1
    Join Date
    Jun 2009
    Location
    Chi town. IL68 ICAO code home airport, literally.
    Posts
    157

    resolved [RESOLVED] Multiple PDO DB connections

    Hello all. I am trying to connect to multiple databases but testing lines of code one at a time, but I dont get any of my messages to echo out onto the page. Now the question is, does my code fail? Or did i write it wrong? No log is created this time around so I am assuming its not failing (Last time I wrote this and tested, there would be an error log created, this time no error log)

    Anyone have any idea??

    Code:
    <?php
    //trys to connect to each database
    try {
    $db1 = new PDO('mysql:harcerze_******; host=**.***.***.***', '*********', '*********');
    } catch (PDOException $ex) {
    	if($db1 == false)
    		echo 'Connect Failed: ' .$ex->getMessage();
    			else {echo 'Connected to DB1';}
    };
    ?>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,633
    Code in the catch{} block will only run if an exception occurs, so you'll never see the success message in there.
    PHP Code:
    try {
        
    $db1 = new PDO('mysql:harcerze_******; host=**.***.***.***''*********''*********');
        echo 
    "<p>Debug: connected to DB1</p>\n";
        
    $db1->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
        
    // continue doing whatever you want with $db1 . . .
    } catch (PDOException $ex) {
        
    $msg $ex->errorInfo;
        
    error_log(var_export($msgtrue));
        die(
    "<p>Sorry, there was an unrecoverable database error. Debug data has been logged.</p>");
    }; 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles