Skip to content

Instantly share code, notes, and snippets.

@az1979
Last active April 14, 2017 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save az1979/e5e85e157ace7d506f8b3fd2c9c5d489 to your computer and use it in GitHub Desktop.
Save az1979/e5e85e157ace7d506f8b3fd2c9c5d489 to your computer and use it in GitHub Desktop.
WordPressプラグイン作成 - データベース テーブル作成
<?php
public function createDatabaseTable()
{
global $wpdb;
$charsetCollate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE {$this->tableName} (
id VARCHAR(8) NOT NULL,
datetime_register DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
datetime_renewal DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
name VARCHAR(20) NOT NULL,
data TEXT NOT NULL,
PRIMARY KEY (id)
) {$charsetCollate};";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment