/    Sign up×
Community /Pin to ProfileBookmark

PHP PDO undefined method PDOStatement::prepare()

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

[code=php]PHP Fatal error: Call to undefined method PDOStatement::prepare() in /home1/harcerze/public_html/DB/confirm.php on line 222[/code]

Now the code in question is below….

[code=php]try {
$firstWORDPRESS = new PDO(‘mysql:host=localhost; dbname=*****’, ‘*******’, ‘******’);
$firstWORDPRESS->setAttribute(PDO::ATTR_ERRMODE, PDO::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($msg, true));
die(“<p>Sorry, there was a unrecoverable database error with 1-SZA WordPress Account. Debug data has been logged.</p>”);
}[/code]

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?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@simplypixieDec 01.2012 — I don't use PDO but shouldn't your query have 'placeholders' rather than actual variables, something like this
[code=php]$grab = $firstWORDPRESS->prepare("SELECT ID FROM wp_users WHERE user_email = ?");
//Executes this little SQL Statement
$grab->execute(array($email));[/code]
Copy linkTweet thisAlerts:
@ZABIDec 01.2012 — as error says your are making a 'Call to undefined method PDOStatement::prepare()', check if there is no spelling mistake, also the related library is being loaded properly.

i am not much used to with PDO anyway.
Copy linkTweet thisAlerts:
@UAL225authorDec 01.2012 — 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.
Copy linkTweet thisAlerts:
@DerokorianDec 01.2012 — 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::prepare 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.
×

Success!

Help @UAL225 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...