Original Poster Posted March 24, 2013 Share Posted March 24, 2013 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 More sharing options...
0 Niekess Posted March 24, 2013 Share Posted March 24, 2013 Are you sure the "PDO" is a database object? The error kind of says it isn't. Link to comment Share on other sites More sharing options...
0 Original Poster Posted March 24, 2013 Author Share Posted March 24, 2013 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 More sharing options...
0 +virtorio MVC Posted March 24, 2013 MVC Share Posted March 24, 2013 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 More sharing options...
0 The_Decryptor Veteran Posted March 24, 2013 Veteran Share Posted March 24, 2013 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 More sharing options...
0 Original Poster Posted March 24, 2013 Author Share Posted March 24, 2013 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 More sharing options...
Question
Original Poster
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
Link to comment
Share on other sites
5 answers to this question
Recommended Posts