1,把php生成的創(chuàng)建表格語句在mysql客戶端里運(yùn)行,看能不能成功,如果語法錯(cuò)誤會(huì)有提示;
創(chuàng)新互聯(lián)從2013年創(chuàng)立,先為正陽等服務(wù)建站,正陽等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為正陽企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
2,檢查mysql用戶是否有權(quán)限創(chuàng)建表;
首先你把這個(gè)sql語句賦給一個(gè)字符串變量:
$sql="CREATE TABLE IF NOT EXISTS `{$installer-getTable('catalog_category_description')}` (
`category_id` mediumint(8) unsigned NOT NULL,
`language_id` smallint(5) unsigned NOT NULL,
`name` varchar(128) NOT NULL,
`description` text NOT NULL,
`meta_title` varchar(128) NOT NULL,
`meta_description` text NOT NULL,
`meta_keyword` varchar(255) NOT NULL,
PRIMARY KEY (`category_id`,`language_id`),
KEY `i_language_id` (`language_id`),
CONSTRAINT `fk_category_id` FOREIGN KEY (`category_id`) REFERENCES `{$installer-getTable('catalog_category')}` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_language_id` FOREIGN KEY (`language_id`) REFERENCES `{$installer-getTable('locale_language')}` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC";
然后連接mysql數(shù)據(jù)庫,執(zhí)行這個(gè)語句:
mysql_connect("localhost","root","");
mysql_select_db("dbname");
mysql_query($sql);
就可以了。
注意連接數(shù)據(jù)庫帳號的權(quán)限要有創(chuàng)建表的權(quán)限,否則創(chuàng)建就不會(huì)成功!
創(chuàng)建數(shù)據(jù)庫:create database 數(shù)據(jù)庫名
創(chuàng)建數(shù)據(jù)表:
CREATE TABLE `users` (
`id` tinyint(10) auto_increment primary key NOT NULL,
`username` varchar(30) NOT NULL,
`age` int(10) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
執(zhí)行這兩個(gè)sql語句就行