1

I do an insert to database using this and this example, but I've got an error message: Call to a member function execute() on a non-object. If I do INSERT INTO participants(email) VALUES ('$email') evrething is OK. Where is my mistake?

$pdo = new PDO('sqlite:participants.db');
$insert = $pdo->prepare("INSERT INTO participants(email) SELECT $email WHERE NOT EXISTS(SELECT 1 FROM participants WHERE email = $email);");
$insert->execute();

UPD:

This is what var_dump($insert) gives:

object(PDOStatement)#2 (1) {
  ["queryString"]=>
  string(65) "INSERT INTO participants (email) VALUES ('paekov@gmail.com')"
}
Community
  • 1
  • 1
rel1x
  • 2,351
  • 4
  • 34
  • 62

1 Answers1

1

Looks like your query needs some modification.

$pdo = new PDO('sqlite:participants.db');
$insert = $pdo->prepare("INSERT INTO participants(email) SELECT :email WHERE NOT EXISTS(SELECT 1 FROM participants WHERE email = :email)");
$insert->execute(array(':email' => $email));
Gopakumar Gopalan
  • 1,187
  • 14
  • 22