2012-09-06 188 views
0

什麼是在PHP中的最佳方式,或一些邏輯......這個表模板創建數據庫模板

 
$tmpl ="CREATE TABLE `wpsc_claimed_stock` (
    `product_id` bigint(20) unsigned NOT NULL DEFAULT '0', 
    `variation_stock_id` bigint(20) unsigned NOT NULL DEFAULT '0', 
    `stock_claimed` float NOT NULL, 
    `last_activity` datetime NOT NULL, 
    `cart_id` varchar(255) NOT NULL DEFAULT '0', 
    `cart_submitted` varchar(1) NOT NULL DEFAULT '0', 
    UNIQUE KEY `unique_key` (`product_id`,`variation_stock_id`,`cart_id`), 
    KEY `last_activity` (`last_activity`), 
    KEY `cart_submitted` (`cart_submitted`) 
)"; 

轉換成這種格式: 注:此snipplet從WP-電子商務拍攝(WordPress插件)

 
$table_name = 'wpsc_claimed_stock'; /* !wpsc_claimed_stock */ 
$wpsc_database_template[$table_name]['columns']['product_id'] = "bigint(20) UNSIGNED NOT NULL DEFAULT '0' "; 
$wpsc_database_template[$table_name]['columns']['variation_stock_id'] = "bigint(20) UNSIGNED NOT NULL DEFAULT '0' "; 
$wpsc_database_template[$table_name]['columns']['stock_claimed'] = "FLOAT NOT NULL "; 
$wpsc_database_template[$table_name]['columns']['last_activity'] = "DATETIME NOT NULL "; 
$wpsc_database_template[$table_name]['columns']['cart_id'] = "VARCHAR(255) NOT NULL DEFAULT '0' "; 
$wpsc_database_template[$table_name]['columns']['cart_submitted'] = "VARCHAR(1) NOT NULL DEFAULT '0' "; 
$wpsc_database_template[$table_name]['indexes']['unique_key'] = "UNIQUE KEY `unique_key` (`product_id`,`variation_stock_id`,`cart_id`)"; 
$wpsc_database_template[$table_name]['indexes']['last_activity'] = "KEY `last_activity` (`last_activity`)"; 
$wpsc_database_template[$table_name]['indexes']['cart_submitted'] = "KEY `cart_submitted` (`cart_submitted`)"; 

回答

0

我認爲最好的方法(也許是唯一的方法)是簡單地編寫一個自定義分析器。我真的沒有看到任何其他方式去做。