Sign in to follow this  
Followers 0
Original Poster

need a PHP error check!?

6 posts in this topic

below is my code... its being called from another function I am getting this error

FATAL ERROR: Call to a member function prepare() on a non-object

can anyone spot my mistake?? thanks for help


public function newPData($AL1, $AL2, $town, $county, $phone, $ID)
{


$ig = $this->PDO->prepare("INSERT INTO `PD`(`AL1`, `AL2`, `TOWN`, `COUNTY`, `ID`, `PHONE`)VALUES(:AL1, :AL2, :TOWN, :COUNTY, :ID, :PHONE)");
$ig->execute(array( ':AL1' => $AL1,
':AL2' => $AL2,
':TOWN' => $town,
':COUNTY' => $county,
':ID' => $ID,
':PHONE' => $phone
));

}
[/CODE]

Share this post


Link to post
Share on other sites

Are you sure the "PDO" is a database object? The error kind of says it isn't.

Share this post


Link to post
Share on other sites

Are you sure the "PDO" is a database object? The error kind of says it isn't.

yes 100% sure all my other code works but this

Share this post


Link to post
Share on other sites

You'd only get that error if PDO hasn't been initialised or is set to a non-object type.

Run this code and paste the output here:

var_dump($this->PDO);

Share this post


Link to post
Share on other sites

Personally I'd put the prepare statement next to where you initialize the PDO connection, so it isn't created/destroyed every time the function is run, and it'd also negate any scoping issues, etc.

Share this post


Link to post
Share on other sites

dont worry got it sorted I was calling a new bject within the class where an object had originally been created in order to call the new object :p ... just had to put in "$this->"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.