Results 1 to 4 of 4

Thread: Mind Boggling PDO Query Failure

  1. #1
    shawntc is offline x10Hosting Member
    Join Date
    Jan 2010
    Posts
    65

    Mind Boggling PDO Query Failure

    I have set up a basic "guestbook" script. It uses a table named guestbook and currently has two rows in it. Using the mysql_* commands I can successfully access the table and display the information as desired. However, I'm trying to look into PDO and currently am attempting to convert the code to PDO. I'm having a bizarre error, though.

    PHP Code:
      // Connect to the database.
    $con=new PDO("mysql:localhost;dbname=db","username","password");

      
    // Grab the data.
      
    $select="SELECT * FROM guestbook";
      
    $data=$con->query($select);
      if(!
    $data){
      echo 
    "Whoops";
      }else{
        echo 
    "Good so far";
      }

      
    $con=null
    The code always echo's "Whoops" as apparently, the query() command fails to retrieve any data. When I do var_dump($data), the output is bool(false). I've tried searching the Internet but found no satisfactory solutions. I know for a fact that there are two rows of data in the table guestbook, yet query() is failing to retrieve them. Can anyone help me understand what's wrong? Does Boru not have part or all of PDO enabled?

    (And before anyone says anything, I realize there are such thing as prepared statements. I'm just starting with PDO, cut me some slack. ;) )
    Last edited by shawntc; 05-26-2012 at 06:59 PM.
    For God so loved the world that he gave is one and only son, that whoever believes in him shall not perish but have eternal life. - John 3:16
    MY SITE!

  2. #2
    gomarc's Avatar
    gomarc is offline x10 Elder
    Join Date
    Oct 2007
    Location
    USA
    Posts
    513

    Re: Mind Boggling PDO Query Failure

    Hi shawntc,

    Your connection sequence is not complete. Try:

    Code:
    $con=new PDO("mysql:host=localhost;dbname=db","username","password");

  3. #3
    shawntc is offline x10Hosting Member
    Join Date
    Jan 2010
    Posts
    65

    Re: Mind Boggling PDO Query Failure

    Quote Originally Posted by gomarc View Post
    Hi shawntc,

    Your connection sequence is not complete. Try:

    Code:
    $con=new PDO("mysql:host=localhost;dbname=db","username","password");
    The forum resounds with the noise of a thousand facepalms. Thanks, it works now.
    For God so loved the world that he gave is one and only son, that whoever believes in him shall not perish but have eternal life. - John 3:16
    MY SITE!

  4. #4
    ellescuba27 is offline x10 Lieutenant
    Join Date
    Sep 2011
    Posts
    267

    Re: Mind Boggling PDO Query Failure

    This is unrelated but I must saw shawntc that you have a lot of interesting projects on your site that I would've never thought of. Good work.

Similar Threads

  1. Mind-boggling Keyboard Prob - Any solutions pls ???
    By mylifestyle in forum Off Topic
    Replies: 2
    Last Post: 10-10-2010, 05:20 AM
  2. on off on off wtf make up your mind
    By spork in forum Free Hosting
    Replies: 2
    Last Post: 12-21-2007, 11:32 AM
  3. don't mind me
    By altrock182182 in forum Introductions
    Replies: 0
    Last Post: 12-10-2007, 07:02 PM
  4. In the mind
    By zak92 in forum Free Hosting
    Replies: 12
    Last Post: 12-07-2006, 02:56 PM

Posting Permissions

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