2

I've hit a wall with a PDO insert:

$q = $dbh->prepare('INSERT INTO grant (grant_name, update) VALUES (?,?)');
$q->bindParam(1, $grant_name, PDO::PARAM_STR);
$q->bindParam(2, $update, PDO::PARAM_STR);
$q->execute();

I get an error:

 PHP Warning:  PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; 

But I cannot find the problem. I have tried using placeholder (such as :grant_name) and using the question marks (?).

4
  • 2
    Not sure, but isn't "update" a reserved word? Try putting update in backticks. Commented Jul 19, 2011 at 20:05
  • It fails even with a single field, such as $grant_name. Commented Jul 19, 2011 at 20:10
  • 1
    That's because GRANT is a reserved word as well! Commented Jul 19, 2011 at 20:11
  • @Brad: haha, d'oh, I completely missed that! Commented Jul 19, 2011 at 20:14

2 Answers 2

6

Both GRANT and UPDATE have specific meanings in SQL. Try this:

$q = $dbh->prepare('INSERT INTO `grant` (`grant_name`, `update`) VALUES (?,?)');
Sign up to request clarification or add additional context in comments.

Comments

1

Having a column name of UPDATE would appear to be your problem. Try quoting the column name (or changing the column name to something that's not a reserved word).

Comments

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.