在joomla-database下的joomla2.5编程中创建表语法

时间:2013-04-16 09:47:14

标签: joomla joomla2.5 joomla-extensions

$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->CREATE TABLE IF NOT EXISTS `tbl_employee` ( `employee_id` int(10) NOT NULL, `name` varchar(50) NOT NULL, `email_id` varchar(40) NOT NULL, `contact_number` int(20) NOT NULL, `address` varchar(300) NOT NULL, `date_of_birth` date NOT NULL, `nationality` varchar(20) NOT NULL, `gender` varchar(10) NOT NULL, `date_of_joining` date NOT NULL, `employee_group_id` int(10) NOT NULL, `cast` varchar(20) NOT NULL, `religion` varchar(20) NOT NULL, `marital_status` varchar(20) NOT NULL, `nominee_name` varchar(60) NOT NULL, `father_name` varchar(60) NOT NULL, `mother_name` varchar(60) NOT NULL, PRIMARY KEY (`employee_id`), KEY `employee_group_id` (`employee_group_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
$db->setQuery($query);

产生错误

  

SCREAM:忽略错误抑制(!)解析错误:语法错误,   意外的'TABLE'(T_STRING)in   C:\瓦帕\ WWW \的Joomla \部件\ com_lmeinstaler \视图\ lmeinstaler \ TMPL \如default.php   第7行

任何人都可以告诉我哪里出错了吗?

1 个答案:

答案 0 :(得分:1)

尝试使用以下内容创建表格:

$db = JFactory::getDBO();
$query = "CREATE TABLE IF NOT EXISTS `#__employee` ( `employee_id` int(10) NOT NULL, `name` varchar(50) NOT NULL, `email_id` varchar(40) NOT NULL, `contact_number` int(20) NOT NULL, `address` varchar(300) NOT NULL, `date_of_birth` date NOT NULL, `nationality` varchar(20) NOT NULL, `gender` varchar(10) NOT NULL, `date_of_joining` date NOT NULL, `employee_group_id` int(10) NOT NULL, `cast` varchar(20) NOT NULL, `religion` varchar(20) NOT NULL, `marital_status` varchar(20) NOT NULL, `nominee_name` varchar(60) NOT NULL, `father_name` varchar(60) NOT NULL, `mother_name` varchar(60) NOT NULL, PRIMARY KEY (`employee_id`), KEY `employee_group_id` (`employee_group_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$db->setQuery($query);
$db->query();

很少进行小调整,主要是添加数据库前缀