Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将数据插入Wordpress数据库时出错。SQLSTATE[HY093]:参数编号无效_Php_Mysql_Wordpress_Pdo - Fatal编程技术网

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

Php 将数据插入Wordpress数据库时出错。SQLSTATE[HY093]:参数编号无效,php,mysql,wordpress,pdo,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_sta

我正在尝试制作一个代码,可以在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++;
              }
我已经检查了好几次,没有一个值是空的,因为Wordpress wp_posts表中的所有字段都设置为要求非空值。这是我的
$post
数组的
var\u dump
,它包含我发送到数据库的所有值:

/var/www/fs/plugins/importador\u-woocommerce/controller/importador\u-woocommerce.php:115:
阵列(大小=18)
“post_author”=>int 1
“post_title”=>字符串“SIME BRAVA SLIM 25BF ESTANCA NATURAL Ioniada 8112500”(长度=53)
“发布内容”=>字符串“”(长度=0)
“post_摘录”=>字符串“”(长度=0)
“发布状态”=>字符串“发布”(长度=7)
'comment_status'=>字符串'closed'(长度=6)
“ping_状态”=>字符串“已关闭”(长度=6)
“post_密码”=>字符串“”(长度=0)
'post_name'=>字符串“”(长度=0)
'to_ping'=>字符串“”(长度=0)
“ping”=>字符串“”(长度=0)
“内容过滤后”=>字符串“”(长度=0)
“post_parent”=>int 0
'guid'=>string'http://fs.local/?post_type=product&p='(长度=37)
“菜单顺序”=>int 0
“post_类型”=>字符串“产品”(长度=7)
“post\u mime\u type'=>字符串“”(长度=0)
“注释计数”=>int 0

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

我的表格结构:

非常感谢您的帮助。提前谢谢

$currenttime= current_time( 'mysql' ); 

将此
$currenttime
而不是
now()
放置在
post\u modified/post\u modified\u gmt

不应该
ID
是AI吗?发布日期应该是当前时间戳吗?这种使用命名占位符显示的方式是否检查过?我已经修改了几次代码,我很确定你是绝对正确的。但由于某种原因,我的笨眼睛让我今天陷入了这一困境。你能发布你在变量和表列定义中发送的内容吗?将每个变量与列类型ex进行比较。如果您将数字作为varchar发送,并且在DB中定义为integer等。感谢您的建议,但是我执行代码的地方不是Wordpress安装。我试图从外部PHP应用程序而不是Wordpress代码中在Wordpress数据库中插入数据。然后从现在开始删除双引号,just place now()从现在开始删除引号()会导致脚本崩溃,因为它是MYSQL函数,而不是PHP函数,因此PHP说我的函数未定义。@SachinIngale
now()
是php中未定义的函数,当传递此日期(“Y-m-d H:i:s”)