• 0

need a PHP error check!?


Question

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]

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

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

Link to comment
Share on other sites

  • 0

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);

Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

  • 0

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->"

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.