Binding insert "fail" on execution
Welcome,
I have following table
Field Type Null Key Default Extra
topic_id int(10) unsigned NO PRI NULL auto_increment
topic_uri varchar(255) NO MUL
forum_id int(11) NO MUL 0
topic_title varchar(255) NO
when int(11) NO 开发者_运维百科0
topic_posts int(11) NO 0
first_post_user varchar(32) NO 0
first_post_when int(11) NO 0
last_post_user varchar(32) NO
last_post_when int(11) NO 0
topic_sticky int(11) NO 0
topic_locked tinyint(4) NO 0
topic_hidden tinyint(4) NO 0
I want make INSERT, using PDO binding.
$b=$dbh->prepare("INSERT INTO `mybase`.`bx_forum_topic` (`topic_id`,`topic_uri`,`forum_id`,`topic_title`,`when,topic_posts`,`first_post_user`,`first_post_when`,`last_post_user`,`last_post_when`,`topic_sticky`,`topic_locked`,`topic_hidden`) VALUES (NULL,:topic_uri,:forum_id,:topic_title,:when,:topic_posts,:first_post_user,:first_post_when,:last_post_user,:last_post_when,:topic_sticky,:topic_locked,:topic_hidden)");
$test=12;
$b->bindParam(":topic_uri",$test);
$b->bindParam(":forum_id",$test);
$b->bindParam(":topic_title",$test);
$b->bindParam(":when",$test);
$b->bindParam(":topic_posts",$test);
$b->bindParam(":first_post_user",$test);
$b->bindParam(":first_post_when",$test);
$b->bindParam(":last_post_user",$test);
$b->bindParam(":last_post_when",$test);
$b->bindParam(":topic_sticky",$test);
$b->bindParam(":topic_locked",$test);
$b->bindParam(":topic_hidden",$test);
$b->execute();
print_r($dbh->errorInfo());
echo $dbh->errorCode();
It don't show ANY ERROR. Error table shows Array ( [0] => 00000 ) 00000
, but no data going inside my table.
When I use without binding:
$b=$dbh->prepare("INSERT INTO `mybase`.`bx_forum_topic` (`topic_id`, `topic_uri`, `forum_id`, `topic_title`, `when`, `topic_posts`, `first_post_user`, `first_post_when`, `last_post_user`, `last_post_when`, `topic_sticky`, `topic_locked`, `topic_hidden`) VALUES (NULL, '12', '12', '12', '12', '12', '12', '12', '12', '12', '12', '12', '12')");
$b->execute();
print_r($dbh->errorInfo());
echo $dbh->errorCode();
It's working.
Where have I made a mistake? Why does it fail and not show any error with binding?
The problem is here I think:
`when,topic_posts`
精彩评论