创建数据库模板

时间:2012-09-06 03:51:22

标签: php

什么是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-ecommerce(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` )";

1 个答案:

答案 0 :(得分:0)

我认为最好的方法(也许是唯一的方法)就是简单地编写自定义解析器。我真的没有看到任何其他方法。