admin管理员组文章数量:1330430
I'm using following install function with dbDelta as referring to the codex, articles on SO I watched out for the typical problems with e.g. one space instead of two spaced at the PRIMARY KEY ...
function myplugin_install(){
global $wpdb;
$table_name = $wpdb->prefix . "vehicles";
$sql = "CREATE TABLE IF NOT EXISTS $table_name
(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
description VARCHAR(25) NOT NULL,
PRIMARY KEY (id)
);
";
$sql .= "CREATE TABLE IF NOT EXISTS $table_name1
(
...
)";
$sql .= "CREATE TABLE IF NOT EXISTS $table_nameX
(
id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
art_alarmierung VARCHAR(25) NOT NULL ,
PRIMARY KEY (id)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
echo $wpdb->last_error;
}
dbDelata only stores the last $sql
variable. And echo $wpdb->last_error;
don't show any errors?
Where is my failure?
BR; mybecks
I'm using following install function with dbDelta as referring to the codex, articles on SO I watched out for the typical problems with e.g. one space instead of two spaced at the PRIMARY KEY ...
function myplugin_install(){
global $wpdb;
$table_name = $wpdb->prefix . "vehicles";
$sql = "CREATE TABLE IF NOT EXISTS $table_name
(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
description VARCHAR(25) NOT NULL,
PRIMARY KEY (id)
);
";
$sql .= "CREATE TABLE IF NOT EXISTS $table_name1
(
...
)";
$sql .= "CREATE TABLE IF NOT EXISTS $table_nameX
(
id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
art_alarmierung VARCHAR(25) NOT NULL ,
PRIMARY KEY (id)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
echo $wpdb->last_error;
}
dbDelata only stores the last $sql
variable. And echo $wpdb->last_error;
don't show any errors?
Where is my failure?
BR; mybecks
Share Improve this question asked May 9, 2012 at 17:04 mybecksmybecks 3511 gold badge6 silver badges17 bronze badges2 Answers
Reset to default 9Run dbDelta
for each SQL statement seperately:
function myplugin_install(){
global $wpdb;
$table_name = $wpdb->prefix . "vehicles";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
$sql = "CREATE TABLE IF NOT EXISTS $table_name
(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
description VARCHAR(25) NOT NULL,
PRIMARY KEY (id)
);
";
dbDelta($sql);
$sql2 = "CREATE TABLE IF NOT EXISTS $table_name1
(
...
)";
dbDelta($sql2);
$sql3 = "CREATE TABLE IF NOT EXISTS $table_nameX
(
id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
art_alarmierung VARCHAR(25) NOT NULL ,
PRIMARY KEY (id)
);";
dbDelta($sql3);
}
For those trying to understand how some plugins, like WooCommerce, are able to do that without calling dbDelta
for every table, the reason is the IF NOT EXISTS
part of query. The dbDelta
function creates an index based on what comes after CREATE TABLE
, so it ends up guessing that all queries create the same table.
If you got here, try to use just CREATE TABLE tablename
and it will work :)
本文标签: pluginsdbDelta only creates the last table
版权声明:本文标题:plugins - dbDelta only creates the last table 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742260987a2442507.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论