www.webdeveloper.com
Results 1 to 5 of 5

Thread: PHP PDO undefined method PDOStatement::prepare()

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

    PHP PDO undefined method PDOStatement::prepare()

    Hello all. So I am getting this buggy issue..

    PHP Code:
    PHP Fatal error:  Call to undefined method PDOStatement::prepare() in /home1/harcerze/public_html/DB/confirm.php on line 222 
    Now the code in question is below....

    PHP Code:
    try {
    $firstWORDPRESS = new PDO('mysql:host=localhost; dbname=*****''*******''******');
    $firstWORDPRESS->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
        
                                                                                                 
    //Now gets ID info from wordpress to be able to insert into META-DATA
    $grab $firstWORDPRESS->prepare
    ("SELECT
    ID
    FROM
    wp_users
    WHERE
    user_email = '
    {$email}'
    "
    );
    //Executes this little SQL Statement
        
    $grab->execute();
        echo (
    "<p>Your abilites have been added to 1sza</p>");
    }        
    //Catches any errors that might have come from updating the wordpress login
    catch (PDOException $ex) {
    $msg $ex->errorInfo;
    error_log(var_export($msgtrue));
    die(
    "<p>Sorry, there was a unrecoverable database error with 1-SZA Wordpress Account.  Debug data has been logged.</p>");

    Now I only gave you the relevant part of the code, because the stuff ahead of this works with out an issue. Anyone see the issue?
    For want of a nail...the horseshoe was lost. For want of a horseshoe, the steed was lost. For want of a steed...the message was not delivered. For want of an undelivered message.....the war was lost.

  2. #2
    Join Date
    Aug 2012
    Posts
    155
    I don't use PDO but shouldn't your query have 'placeholders' rather than actual variables, something like this
    PHP Code:
    $grab $firstWORDPRESS->prepare("SELECT ID FROM wp_users WHERE user_email = ?"); 
    //Executes this little SQL Statement 
    $grab->execute(array($email)); 

  3. #3
    Join Date
    Mar 2009
    Posts
    452
    as error says your are making a 'Call to undefined method PDOStatement:repare()', check if there is no spelling mistake, also the related library is being loaded properly.

    i am not much used to with PDO anyway.

  4. #4
    Join Date
    Jun 2009
    Location
    Chi town. IL68 ICAO code home airport, literally.
    Posts
    157
    Simplypixie, I dont need to have 'placeholders' on it since I am not taking it from a form, its comming right out of a database, hence no possibitlity for injection, hence its set in a varible. As for zabi, checked spelling mutlipule times nada. Also library isnt an issue.
    For want of a nail...the horseshoe was lost. For want of a horseshoe, the steed was lost. For want of a steed...the message was not delivered. For want of an undelivered message.....the war was lost.

  5. #5
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    Like the error says, prepare is not defined for objects of type PDOStatement. It is instead supposed to be on PDO, and the return of PDO:repare is a PDOStatement object. However given the code you've shown, I don't know how you are getting that error since you show $firstWORDPRESS = new PDO, then $firstWORDPRESS->prepare(). However, even though the code you showed us looks correct, the error message suggest you are either showing us snippets with pieces missing, or looking at the wrong code for the error.
    ~Ryan
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 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