• 0

Question

Posted

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


[color="#000000"]FATAL ERROR: [/color]Call to a member function prepare() on a non-object

can anyone spot my mistake?? thanks for help
[CODE]
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

5 answers to this question

  • 0

Posted

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
  • 0

Posted

[quote name='Niekess' timestamp='1364156181' post='595595580']
Are you sure the "PDO" is a database object? The error kind of says it isn't.
[/quote]

yes 100% sure all my other code works but this

Share this post


Link to post
Share on other sites
  • 0

Posted

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:
[code]
var_dump($this->PDO);
[/code]

Share this post


Link to post
Share on other sites
  • 0

Posted

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
  • 0

Posted

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.