我已经成功创建了表格:
function jal_install () {
global $wpdb;
global $jal_db_version;
$table_name = $wpdb->prefix . "liveshoutbox";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT, time bigint(11) DEFAULT '0' NOT NULL, name tinytext NOT NULL, text text NOT NULL, url VARCHAR(55) NOT NULL, UNIQUE KEY id (id) );";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
$welcome_name = "Mr. Wordpress";
$welcome_text = "Congratulations, you just completed the installation!";
$insert = "INSERT INTO " . $table_name .
" (time, name, text) " .
"VALUES ('" . time() . "','" . $wpdb->escape($welcome_name) . "','" . $wpdb->escape($welcome_text) . "')";
$results = $wpdb->query( $insert );
}
}
jal_install ();
但是当我尝试将此表称为WP如何引用其$wpdb->posts
之类的内部表时:
var_dump($wpdb->liveshoutbox);
输出结果为:
null
为什么?
答案 0 :(得分:1)
我知道自从这个帖子出现以来已经有一段时间了,但我想我会分享我是如何解决它的。答案似乎是完整地引用表名,包括没有$ wpdb->的前缀。不确定它适用于var_dump,但它确实用于获取行和结果
答案 1 :(得分:0)
不支持
$wpdb->liveshoutbox
和only internal table have direct access :(例如)
$wpdb->posts
为此,您唯一的选择是:
$wpdb->prefix . "liveshoutbox"