Home  >  Article  >  Backend Development  >  Has anyone used wordpress?

Has anyone used wordpress?

WBOY
WBOYOriginal
2016-12-01 01:27:45908browse

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');

Reply content:

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');

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn