我正在尝试以编程方式在批量操作中插入注释,作为迁移例程的一部分。注释位于SQL server表中。
我从SQL server表字段接收日期信息,并将其存储在PHP变量中,如下所示;
while( $row = sqlsrv_fetch_array( $RS, SQLSRV_FETCH_ASSOC))
{
...
$the_date = $row[\'the_date\'];
...
}
$the\\u日期的var\\u dump视图如下所示;
object(DateTime)#97 (3) {
["date"]=>
string(19) "2012-07-30 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
然后,我准备wp\\u insert\\u注释的数据数组
该数据数组的var\\u dump视图,如下所示;
array(7) {
["comment_post_ID"]=>
string(5) "73615"
["comment_author"]=>
string(14) "Joe (USA)"
["comment_author_email"]=>
string(20) "user@domain.com"
["comment_content"]=>
string(2001) "commment text here"
["comment_parent"]=>
int(0)
["comment_date"]=>
object(DateTime)#97 (3) {
["date"]=>
string(19) "2012-07-30 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
["comment_approved"]=>
int(1)
}
在wp\\u insert\\u comment操作之后,我得到一个0作为返回-表示一个错误。
下面的消息将停止整个过程。
Warning: preg_match() expects parameter 2 to be string, object given in F:\\inetpub\\....\\wp-includes\\formatting.php on line 1868
Fatal error: Uncaught exception \'Exception\' with message \'DateTime::__construct() expects parameter 1 to be string, object given\' in F:\\inetpub\\....\\wp-includes\\formatting.php:1872 Stack trace: #0 F:\\inetpub\\....\\wp-includes\\formatting.php(1872): DateTime->__construct(Object(DateTime)) #1 F:\\inetpub\\....\\wp-includes\\comment.php(1238): get_gmt_from_date(Object(DateTime)) #2 F:\\inetpub\\...\\comments.php(259): wp_insert_comment(Array) #3 F:\\inetpub\\...\\comments.php(100): HandleComments(Resource id #25, \'73615\', \'services.articl...\', \'XYZ1207-5206\') #4 {main} thrown in F:\\inetpub\\....\\wp-includes\\formatting.php on line 1872
如何绕过这个问题并正确存储日期?2012-07-30 00:00:00