将数据插入Wordpress数据库时出错。 SQLSTATE [HY093]:参数号无效

时间:2017-06-06 10:37:31

标签: php mysql wordpress pdo

我正在尝试制作可以在WooCommerce安装(Wordpress)中插入产品的代码。我一直收到这个错误,即使在数据库表(23列),查询(23列)和值(也是23)中参数计数似乎都很好。我想有些事情是错的,但无论我检查代码多少次,对我来说一切都很好。

$sqlinsert = "INSERT INTO wp_posts (ID,post_author,post_date,post_date_gmt,post_content,post_title,post_excerpt,post_status,comment_status,ping_status,post_password,post_name,to_ping,pinged,post_modified,post_modified_gmt,post_content_filtered,post_parent,guid,menu_order,post_type,post_mime_type,comment_count) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
              $sth = $dbh->prepare($sqlinsert);

              if($sth->execute(array(
                 "ID" => $id,
                 "post_author" => $post_author,
                 "post_date" => "NOW()",
                 "post_date_gmt" => "NOW()",
                 "post_content" => $post_content,
                 "post_title" => $post_title,
                 "post_excerpt" => $post_excerpt,
                 "post_status" => $post_status,
                 "comment_status" => $comment_status,
                 "ping_status" => $ping_status,
                 "post_password" => $post_password,
                 "post_name" => $post_name,
                 "to_ping" => $to_ping,
                 "pinged" => $pinged,
                 "post_modified" => "NOW()",
                 "post_modified_gmt" => "NOW()",
                 "post_content_filtered" => $post_content_filtered,
                 "post_parent" => $post_parent,
                 "guid" => $guid,
                 "menu_order" => $menu_order,
                 "post_type" => $post_type,
                 "post_mime_type" => $post_mime_type,
                 "comment_count" => $comment_count
              ))){
                 $contadorinsert++;
              }else{
                 $contadorerror++;
              }

我已多次检查过没有值为NULL,因为Wordpress wp_posts表中的所有字段都设置为需要NOT NULL值。这是我的var_dump数组的$post,其中包含我发送到数据库的所有值:

/var/www/fs/plugins/importador_woocommerce/controller/importador_woocommerce.php:115: array (size=18) 'post_author' => int 1 'post_title' => string 'SIME BRAVA SLIM 25BF ESTANCA NATURAL IONIZADA 8112500' (length=53) 'post_content' => string '' (length=0) 'post_excerpt' => string '' (length=0) 'post_status' => string 'publish' (length=7) 'comment_status' => string 'closed' (length=6) 'ping_status' => string 'closed' (length=6) 'post_password' => string '' (length=0) 'post_name' => string '' (length=0) 'to_ping' => string '' (length=0) 'pinged' => string '' (length=0) 'post_content_filtered' => string '' (length=0) 'post_parent' => int 0 'guid' => string 'http://fs.local/?post_type=product&p=' (length=37) 'menu_order' => int 0 'post_type' => string 'product' (length=7) 'post_mime_type' => string '' (length=0) 'comment_count' => int 0

Wordpress原始wp_posts表具有以下结构(对于较新版本的Wordpress,使用utf8mb4_unicode_520_ci编码而不是ut8_general_ci):

我的表结构:

enter image description here

非常感谢任何帮助。提前谢谢。

1 个答案:

答案 0 :(得分:0)

$currenttime= current_time( 'mysql' ); 

将此$currenttime而不是now()放在post_modified/post_modified_gmt