Wordpress dbDelta无法正常工作 [英] Wordpress dbDelta not functioning

查看:26
本文介绍了Wordpress dbDelta无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为客户编写插件,尽管通常可以正常工作,但我发现dbDelta不允许我创建激活插件时所需的表.

I'm currently writing a plugin for a customer, and while it's usually working good, I found that dbDelta does not allow me to create the table I need on plugin activation.

我正在运行以下代码来绑定激活功能:

I'm running the below code to bind the activation function:

register_activation_hook(__FILE__, 'adminInstallation');

这是函数本身:

function adminInstallation(){
    global $wpdb;

    $objectEquipment = 'wp_object_equipment';
    $equipmentSQL = "CREATE TABLE ".$objectEquipment." (
                    id mediumint(9) NOT NULL AUTO_INCREMENT,
                    name tinytext NOT NULL
                );";

    require_once(ABSPATH.'wp-admin/includes/upgrade.php');
    $equipment = dbDelta($equipmentSQL);
}

运行此命令后,我正在检查数据库,但未添加任何表.尝试转储错误只会导致Wordpress告诉我有意外的输出,但不会让我看到服务器返回的实际消息.这个问题困扰了我几个小时,在解决之前我无法继续.这里有人知道为什么会这样做吗?

Once this has been run, I am checking the database, but no tables have been added. Trying to dump the error will only result in Wordpress telling me there was unexpected output, but it wont let me see the actual message that the server returns. This issue has been bugging me for some hours, and I cant continue until it's solved. Does anyone here have any idea why it might do this?

据我所知,所有代码都是有效的,这是我编写的第三个插件.我什至尝试使用以前代码中的代码,但这也不起作用.

As far as I can tell, all the code is valid, and this is the third plugin I've written. I even tried using the code from my previous ones, but that did not work either.

插件激活后,我尝试运行该函数并转储dbDelta响应.它报告表已创建,但是数据库中没有新内容.有什么想法吗?

提前谢谢!//乔纳森

推荐答案

在dbDelta调用后应 echo $ wpdb-> last_error; ,这样您将得到mysql错误.

You shoud echo $wpdb->last_error; after dbDelta call so you get the mysql error.

这篇关于Wordpress dbDelta无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆