Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am attempting to have my plugin create a new table. I am fairly new to SQL. I have found two different method for creating tables:

Method I

$table_name = $wpdb->prefix . 'cool_table';
$sql = "CREATE TABLE $table_name (
    [command to set up columns go here]
    ) DEFAULT CHARSET=utf8;";

Method II

if ( ! empty($wpdb->charset) )
    $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
if ( ! empty($wpdb->collate) )
    $charset_collate .= " COLLATE $wpdb->collate";

$table_name = $wpdb->prefix . 'cool_table';

$sql = "CREATE TABLE $table_name (
    [command to set up columns go here]
    ) ENGINE = InnoDB {$charset_collate};";

What is the benefit of setting the default charset vs. setting the ENGINE when creating a new table?

share|improve this question
    
This is a MySQL question but the charset and the database engine are different animals. Your two blocks of code do different things. –  s_ha_dum Apr 13 '13 at 2:39
    
What do you mean? Do these two pieses of code not both set up a SQL statement that can be used with the dbDelta() function in order to create a new table in the database? –  William Apr 13 '13 at 4:45
    
But the second-- the ENGINE one-- changes the database engine to InnoDB for the table created. The first creates the table using the server default database engine, which used to be MYISAM but I heard a rumor that that was changing. –  s_ha_dum Apr 13 '13 at 13:34
    
Yea my understanding is that the most recent version of MySQL is using InnoDB as the default. When I specify the engine here, does it change it for the entire database or just the table? Also, is there a reason for me to set the default charset when creating a table? What are the implications of this? –  William Apr 13 '13 at 16:17
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.