3

I currently have the following code:

$dbh = new PDO('mysql:host='.DATABASE_HOST.';dbname='.DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

$dbh->prepare("INSERT INTO mdr_contacts SET fkRelatieId = 0, reseller = 0, code = :code, naam = :naam");
$dbh->execute(array(":code" => $contact["contact_id"],":naam" => $name));

However this seems to fail: Fatal error: Call to undefined method PDO::execute() in file.php on line 67

What i've done so far to make this work:

  1. Checked if $name and $contact exists and has the right value.
  2. Executed a SELECT query before the prepare statement to make sure that PDO works.
  3. Runned the code without ATTR_EMULATE_PREPARES set to false.

But none of this works, can anyone set me in the right direction?

1 Answer 1

2

You execute a statement, not a connection. prepare() on a connection, returns a statement.

Also, I prefer to explicitly call bind on values, but this is just my OCD prefs.

 $statement = $dbh->prepare("INSERT INTO mdr_contacts SET fkRelatieId = 0, reseller = 0, code = :code, naam = :naam");
 $statement->bindValue(":code", $contact["contact_id"]);
 $statement->bindValue(":naam", $name);
 $statement->execute();
Sign up to request clarification or add additional context in comments.

2 Comments

my god i feel like such an idiot. This completly works. Thanks.
@RTB no problem... also check your spelling of 'name' ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.