0
$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:错误抑制忽略(!)解析错误:语法错误,C:\wamp\www\joomla\components\com_lmeinstaler\views\lmeinstaler\tmpl\default.php 中的意外 'TABLE' (T_STRING) 在第 7 行

谁能告诉我错误在哪里?

4

1 回答 1

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();

做了一些小的调整,主要是添加数据库前缀

于 2013-04-16T13:49:25.150 回答