SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Aggregation when passed object fails

    That title probably made no sense, im sorry.

    This is a line i use to create a new store locator...

    PHP Code:
    $locator = new Locator(new db($host$user$pw$db)); 
    now if the db fails to connect obviously everything falls apart.

    Im wondering if there is a more graceful way to test for db other than

    PHP Code:
    if ($db = new db($host$user$pw$db)) {
        
    $locator = new Locator($db);


  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    5 Thread(s)
    try catch where the db instance throws a exception if it doesn't connect.

    Code:
    try {
      $locator = new Locator(new db($host, $user, $pw, $db));
    } catch(Exception $e) {
      exit;
    }


Bookmarks

Posting Permissions

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