php $wpdb->插入不起作用。没有错误消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20605937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:20:17  来源:igfitidea点击:

$wpdb->insert not working. No Error Msg

phpmysqlwordpresswpdb

提问by KingRichard

Got the lower portion here sorted, but now there's an issue when it inserts the record. I have the NULLvalue for fileformatted as %sfor string, but it's not inserting NULLit's inserting [BLOB - 0B]. The column format in the mySQL table is longblob. Any ideas?

在这里排序了较低的部分,但现在插入记录时出现问题。我有格式化为字符串的NULL值,但它没有插入它正在插入. mySQL 表中的列格式为. 有任何想法吗?file%sNULL[BLOB - 0B]longblob



this is my first time using $wpdb->insertand it looks like I've missed something.

这是我第一次使用$wpdb->insert,看起来我错过了一些东西。

Here's the loop I'm trying to use. There are currently 2 timestamps in the array.

这是我尝试使用的循环。数组中目前有 2 个时间戳。

for ( $i = 0; $i < count($timestamps); $i++ ) {
$working_time = $timestamps[$i];
$working_form = $formnames[$i];

$status_data = array(
    'submit_time' => $working_time,
    'form_name' => $working_form,
    'field_name' => 'lead_status',
    'field_value' => 'new',
    'field_order' => 10001,
    'file' => NULL
);
$status_data_types = array(
    '%f',
    '%s',
    '%s',
    '%s',
    '%d',
    '%s'
);

$result = $wpdb->get_results("SELECT field_value FROM ".$leadtable." WHERE submit_time = ".$working_time);

if(!$result) {              
    $insert = $wpdb->insert($leadtable, $status_data, $status_data_types);
    if( !$insert ) {
            echo 'didn\'t work';
        }
}
}

I know that $working_timeand $working_formare both set properly. $working_timeis a long float like 1387175380.9600and $working_formis a string.

我知道,$working_time并且$working_form都设置正确。$working_time是一个长浮点数1387175380.9600$working_form是一个字符串。

Nothing is being returned, even by the if( !$insert )check so I'm guessing it's erring somewhere before that point. I know that if( !$result )will return true because that data does not exist yet.

没有任何东西被退回,即使是通过if( !$insert )支票,所以我猜它在那之前的某个地方出错了。我知道这if( !$result )将返回 true,因为该数据尚不存在。

Found the issue. The get_results query was failing due to a missed period. My HS English teacher was right... a missed period can be a HUGE problem!

发现问题。由于错过了一段时间,get_results 查询失败。我的 HS 英语老师是对的...错过时间可能是一个巨大的问题!

采纳答案by murison

Maybe your config hides error showing. Have you tried $wpdb->print_error();?

也许您的配置隐藏了错误显示。你试过$wpdb->print_error();吗?

回答by Matija

If you want to get the last error and last query you can use this properties of $wpdbobject:

如果你想得到最后一个错误和最后一个查询,你可以使用$wpdb对象的这个属性:

$wpdb->last_error 

will show you the last error, if you got one.

会告诉你最后一个错误,如果你有一个。

$wpdb->last_query 

will assist you with showing the last query (where the error occurred)

将帮助您显示最后一个查询(发生错误的地方)

I hope this will help you out.

我希望这会帮助你。

回答by Liam Mitchell

https://core.trac.wordpress.org/ticket/32315

https://core.trac.wordpress.org/ticket/323​​15

One of the columns inputs may be larger than the column is. Wordpress detects this and will not even send the query to the DB.

列输入之一可能大于列。Wordpress 检测到这一点,甚至不会将查询发送到数据库。

The Diff there shows a patch for wp-db you can put in to get more information in the last_error message so it will not be empty.

Diff 那里显示了 wp-db 的补丁,您可以放入以获取 last_error 消息中的更多信息,因此它不会为空。

enter image description here

在此处输入图片说明

回答by Rocky Mehta

Hopefully, you define global variable = $wpdb.

希望您定义全局变量 = $wpdb。

If your $wpdb not working, and also not showing any error then you must try these three steps.

如果您的 $wpdb 不起作用,并且也没有显示任何错误,那么您必须尝试这三个步骤。

  1. Print your error using with errors functions.

    echo $wpdb->last_error;

    or

    echo $wpdb->show_errors();

  2. If no error visible then you must print your last query using with last query function.

    echo $wpdb->last_query();

  3. Copy and paste your last query in your Phpmyadmin > Your Database -> Table -> SQL tab, click on Go button, you will definitely get proper solutions(errors) in it.

  1. 使用 with errors 函数打印错误。

    echo $wpdb->last_error;

    or

    echo $wpdb->show_errors();

  2. 如果没有错误可见,那么您必须使用 last query 功能打印您的最后一个查询。

    echo $wpdb->last_query();

  3. 将上一个查询复制并粘贴到您的 Phpmyadmin > Your Database -> Table -> SQL 选项卡中,单击 Go 按钮,您一定会在其中获得正确的解决方案(错误)。

Thanks,

谢谢,

Rocky Mehta.

洛基梅塔。