#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    PDO doesn't return anything


    I've just installed PHP 5.3.3-7 on my Debian server and found that mysqli will work, but pdo doesn't.



    try
    {
    $DBH = new pdo("mysql:host=$host;dbname=$dname", $user, $pass ) ;
    $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    echo '<p>Connected to database' ;

    $DBH->prepare('DELECT name FROM people');

    }
    catch( PDOException $e )
    {
    echo "Error! " ;
    echo $e->getMessage() ;
    }

    will just produce "Connected to database" but doesn't return and error and subsequent pdo queries do nothing (they work under windows and php 5.2.9)

    Any thoughts (and thanks in advance)?
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,539
    Rep Power
    2337
    Read the manual on PDO::prepare(). Note that it returns a PDOStatement object which is then used to execute the query.
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    PDO does nothing


    Let me expand a bit. Forget about that fact that it doesn't output an error. The code below works on my windows/php 5.2 system, but doesn't do anything on my Debian/php 5.3 system.

    try
    {
    $hDB = new pdo("mysql:host=$host;dbname=$dname", $user, $pass ) ;
    $hDB->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    echo '<p>Connected to database' ;
    }
    catch( PDOException $e )
    {
    echo "Error! " ;
    echo $e->getMessage() ;
    }

    $q = "SELECT Lastname, Firstname FROM users" ;
    $hST = $hDB->prepare( $q );
    $result = $hDB->query( $q ) ;
    if( $result !== FALSE )
    {
    $cols = $result->columnCount() ;
    echo "<p>table has $cols columns" ;

    foreach( $result as $row )
    {
    echo "<p>" . $row['Lastname'] . ", " . $row['Firstname'] ;
    }


    }
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,690
    Rep Power
    6351
    Which part isn't working? What have you done to debug? What errors are being thrown by PHP or by MySQL? We can't do anything but tell you what you already know: It should be working since it worked before.

    Also note that the advice you've already been given has not been followed in this most recent code.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    PDO doesn't (really) work


    Intriguingly, I can introduce an error (say by giving a non-existent database) which PDOExceptions will report. Aside from that, nothing is returned from PDO.

    It's not fair to say it has worked before. My code works on a Windows server under php 5.2.9, but this is a new Debian (linux) installation, php 5.3.x. Mysqli works, mysql doesn't and PDO doesn't.
  10. #6
  11. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,298
    Rep Power
    7170
    Is PDO::query returning false? Is it returning at all? You don't catch the exception from it, so if one is being thrown and you don't have error reporting turned on, all you'll get is a blank screen due to the uncaught exception.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Resolved PDO Issue


    e-Oreo, thanks. I put a try/catch around the query and found the error.

    So, PDO is working; I wasn't.
  14. #8
  15. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,690
    Rep Power
    6351
    Hence the reason why I asked:
    Which part isn't working? What have you done to debug? What errors are being thrown by PHP or by MySQL?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo