4

I have following lines:

    $sql = "INSERT INTO news (title, content) VALUES :title, :content";
    $pre = $this->prepare($sql);
    $pre->bindValue(":title", "xxx");
    $pre->bindValue(":content", "yyy");
    $pre->execute();

I get no error, but the query is also not executed (i checked the query log).

I tried following changes desperately:

 $t="xxx" and $pre->bindValue(":title", $t); (the same also for y)
 $sql = "INSERT INTO `news` (`title`, `content`) VALUES :title, :content";
 $sql = "INSERT INTO `news` (`title`, `content`) VALUES ':title', ':content'";

Nothing changes. Funny thing is i get no response, no warning, no error just nothing. But the query is not executed.

I found similar posts but non of them solved my problem.

(about $this ... The code is in a class extended from PDO class.)

3
  • Don't forget about the method errorInfo(). Does that give you any errors? Commented Dec 14, 2013 at 18:50
  • it returns 00000. What does that mean? Commented Dec 14, 2013 at 18:54
  • If you were using a development framework or at least an ORM like Propel or Doctrine you wouldn't need to fuss around with stuff like this. Commented Dec 14, 2013 at 19:54

2 Answers 2

4

try this, your values should be wrapped inside the values()

"INSERT INTO news (title, content) VALUES (:title, :content)";

instead of

"INSERT INTO news (title, content) VALUES :title, :content";
Sign up to request clarification or add additional context in comments.

Comments

3

Try: "INSERT INTO news (title, content) VALUES (:title, :content)";

You must surround the insert values with parentheses. 

1 Comment

It would make your answer a little better if you explained the subtle difference between this and the asker's code.

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.