php - WordPress 替换查询输入 null

标签 php mysql wordpress

我正在使用 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/

相关文章:

javascript - 在 jQuery 中查询字符串中的元素

php - 如何删除 woocommerce 选项卡?

php - NOT LIKE 多个 OR 语句?

PHP 中的 JavaScript(wordpress)

localization - load_plugin_textdomain 不起作用

php - 导航栏仅在 IE 中闪烁

php - 如何在 Markdown 通知中插入换行符

mysql - 从两个年份相同的表中选择值

php - while()中的数据如何划分?

mysql - MYSQL 如何将一个非常大的表复制到另一个表中?