gpt4 book ai didi

php - WordPress 替换查询输入 null

转载 作者:行者123 更新时间:2023-11-29 19:23:10 26 4
gpt4 key购买 nike

我正在使用 wordpress 替换查询来更新/添加记录,但我遇到了错误。它成功更新记录但不在数组中的值变为 null 。这是我的代码

function ux_add_data($table,$postdata){
global $wpdb;
$tablename=$wpdb->prefix.$table;
$updated_data=$postdata['BX_data'];
if(isset($updated_data['isActive']) && $updated_data['isActive']==1)
$updated_data['isActive']=1;
else
$updated_data['isActive']=0;

$data=$wpdb->replace($tablename,$updated_data,array('%s') );
if($data)
return UX_flash('success','Data has been added successfully.');
else
return UX_flash('danger','Some errror to save your data.');
}

如果我在数据库中有列recordid,ID,name,class,created,modified并且在数组中我只有recordid,name,modified然后ID ,class,modified 变为 null 。

请告诉我哪里做错了。

谢谢

最佳答案

您正在使用$wpdb->replace函数,请注意

wpdb::replace( string $table, array $data, array|string $format = null )

$data

(array) (Required) Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case.

因此,当您设置某些列时,其他一些列将设置为 null。

查找更多 at here .

关于php - WordPress 替换查询输入 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42315951/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com