【发布时间】:2016-08-01 17:42:33
【问题描述】:
我想在 Codeigniter 3.1.0 中从我的服务器运行 .sql 文件。我试过关注
//code to create a DB & this is successful then following ocde
$query = file_get_contents('./test.sql');
$this->db->query($query);
这是我的test.sql 文件。 https://gist.github.com/rejoan/97dfae1b08116e386b3e6fda97eeb4f7
现在当我运行它时,它总是显示错误
发生数据库错误
错误号:1064
您的 SQL 语法有错误;检查手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 'CREATE TABLE
user(idint(11) NOT NULL,test_idint(11) NOT NULL, '' 在第 10 行
CREATE TABLE `test`
( `id` int(11) NOT NULL,
`name` varchar(250) NOT NULL,
`description` text NOT NULL,
`added` date NOT NULL,
`outdate` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `user`
( `id` int(11) NOT NULL,
`test_id` int(11) NOT NULL,
`name` varchar(250) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `test` ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `name` (`name`);
ALTER TABLE `user` ADD PRIMARY KEY (`id`),
ADD KEY `test_id` (`test_id`);
ALTER TABLE `test` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=37;
ALTER TABLE `user` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `user`
ADD CONSTRAINT `FK_user_test` FOREIGN KEY (`test_id`)
REFERENCES `test` (`id`) ON UPDATE NO ACTION;
文件名:C:/xampp/htdocs/spider_clients/system/database/DB_driver.php
行号:691
那么我该如何通过问题来解决这个问题呢?我有一个想法通过 PHP 原始代码来做到这一点,但首先我想通过 CI 解决。有什么想法吗?
** 即使我尝试用单引号替换所有反引号仍然无效
【问题讨论】:
-
so Ci 关于这个问题的解决方案?
-
好吧,正如您所说,您需要纯 CI 解决方案。我的链接没有提供。我希望它能帮助你理解问题的想法。
-
我认为您不能在一个语句中运行 多个 查询。您可能需要将其拆分并多次致电
->query()。
标签: php mysql sql database codeigniter