Why I can't access the newly created table in wordpress this way?
I've already created the table successfully:
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 ti开发者_开发技巧nytext 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 ();
But when I try to refer to this table as how WP refers to its internal tables like $wpdb->posts
:
var_dump($wpdb->liveshoutbox);
The output is :
null
Why?
I know it's been a while since this thread appeared, but thought I'd share how I solved it. The answer it seems is to refer to the table name in full including the prefix without $wpdb->. Not sure it it works for var_dump, but it did for getting rows and results
There is no support for
$wpdb->liveshoutbox
and only internal table have direct access to: (eg)
$wpdb->posts
For that, your only option is:
$wpdb->prefix . "liveshoutbox"
精彩评论