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.)

m59
  • 43,214
  • 14
  • 119
  • 136
A.B.
  • 2,374
  • 3
  • 24
  • 40
  • Don't forget about the method [`errorInfo()`](http://www.php.net/manual/en/pdo.errorinfo.php). Does that give you any errors? –  Dec 14 '13 at 18:50
  • it returns 00000. What does that mean? – A.B. Dec 14 '13 at 18:54
  • If you were using a [development framework](http://codegeekz.com/best-php-frameworks-for-developers/) or at least an ORM like [Propel](http://propelorm.org/) or [Doctrine](http://www.doctrine-project.org/projects/orm.html) you wouldn't need to fuss around with stuff like this. – tadman Dec 14 '13 at 19:54

2 Answers2

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";
Krish R
  • 22,583
  • 7
  • 50
  • 59
3

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

You must surround the insert values with parentheses. 

MillaresRoo
  • 3,808
  • 1
  • 31
  • 37
  • It would make your answer a little better if you explained the subtle difference between this and the asker's code. –  Dec 14 '13 at 18:51