http://us.php.net/manual/en/ref.pdo.php $dbh = null;

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim Carlock

    http://us.php.net/manual/en/ref.pdo.php $dbh = null;

    The above page presents the following information...

    Example 1695. Handling connection errors

    <?php
    $DBName = "sqlite:db.sq3" ;
    $user = "admin";
    $pass = "admin";
    try {
    $dbh = new PDO($DBName, $user, $pass);
    $dbh->exec('CREATE TABLE FOO(id INDEX PRIMARY KEY, name TEXT);');
    $dbh = null; // Error or warning. This is the only line I didn't change.
    } catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
    }
    ?>

    The $dbh = null; line coughs up an error. That's one of the only lines I
    did not change from the example presented on that page. It appears
    that the documentation is incorrect. Is that correct?

    The code runs, but I'm left confused about why that line exists.

    Could one use unset($dbh); to kill it? What's the recommended way
    to destroy a PDO object?

    Thanks.

    --
    Jim Carlock


  • Jim Carlock

    #2
    Re: http://us.php.net/manual/en/ref.pdo.php $dbh = null;

    Oops.

    I cancelled the message, but someone may have downloaded it.
    Please disregard the message. I tried to duplicate the problem,
    and it ended up as another problem.

    [15-Jun-2007 19:09:35] PHP Notice: Object of class PDO could not be converted to int in index.php on line 117

    That notice occured on the if() line below...

    $oPDO = new PDO($sDBName, $sUserID, $sPassword);
    if (($oPDO) & (strlen($sSQL) 0)) {

    and not on the...

    $oPDO = null;

    line.

    If someone replies to the message I'll repost it. If not, perhaps
    I still have something here to question. Specifically the line that
    sets $oPDO to null. The webpage in question only presents it
    one time and few (if any) of the other examples use that line.

    My apologies about sending folks off on a wild goose chase in
    the previous message. :-)

    --
    Jim Carlock
    Post replies to the group.


    Comment

    • Rik

      #3
      Re: http://us.php.net/manual/en/ref.pdo.php $dbh = null;

      On Sat, 16 Jun 2007 01:24:42 +0200, Jim Carlock <anonymous@127. 0.0.1
      wrote:
      Oops.
      >
      I cancelled the message, but someone may have downloaded it.
      Please disregard the message. I tried to duplicate the problem,
      and it ended up as another problem.
      >
      [15-Jun-2007 19:09:35] PHP Notice: Object of class PDO could not be
      converted to int in index.php on line 117
      >
      That notice occured on the if() line below...
      >
      $oPDO = new PDO($sDBName, $sUserID, $sPassword);
      if (($oPDO) & (strlen($sSQL) 0)) {
      & = && ?

      & is a bitwise operator, I suspect it tries to cast $oPDO to an integer to
      check this, which cannot be done. It can however be cast to a boolean,
      which is what && does.

      --
      Rik Wasmus

      Comment

      Working...