Home >Backend Development >PHP Tutorial >Has anyone used wordpress?
Has anyone used wordpress before? How can WordPress create a data table? If it can be created, is there any way to operate the created data table? I used the following code. It is said online that it can be used in a plug-in. But it didn’t work for me. I wrote the code wrong or put it in the wrong place
function wp_user_avatars_create_table() {
<code>global $wpdb; $table_name = $wpdb->prefix . "test"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name){ $sql = "CREATE TABLE IF NOT EXISTS " . $tablename . " ( `test_id` int(8) unsigned NOT NULL, `test_name` varchar(200) CHARACTER SET utf8 NOT NULL, `test_password` varchar(200) CHARACTER SET utf8 NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; dbDelta($sql); }</code>
}
register_activation_hook( __FILE__,'wp_user_avatars_create_table');
Has anyone used wordpress before? How can WordPress create a data table? If it can be created, is there any way to operate the created data table? I used the following code. It is said online that it can be used in a plug-in. But it didn’t work for me. I wrote the code wrong or put it in the wrong place
function wp_user_avatars_create_table() {
<code>global $wpdb; $table_name = $wpdb->prefix . "test"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name){ $sql = "CREATE TABLE IF NOT EXISTS " . $tablename . " ( `test_id` int(8) unsigned NOT NULL, `test_name` varchar(200) CHARACTER SET utf8 NOT NULL, `test_password` varchar(200) CHARACTER SET utf8 NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; dbDelta($sql); }</code>
}
register_activation_hook( __FILE__,'wp_user_avatars_create_table');