I'm making a simple script installation, in which the user enters the page, the system tables are created. The SQL code for these tables are in the same directory that I access via the file_get_contents function, and then set to mysql_query.
But always get an error. I do not understand it because when I run the code by phpMyAdmin for example, it goes without any problem. What can it be?
PHP
$sql = file_get_contents("install.sql");
mysql_query($sql) or die("Error: ".mysql_error());
SQL
DROP TABLE IF EXISTS `jogos`;
CREATE TABLE `jogos` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`casaid` varchar(255) NOT NULL,
`foraid` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Error
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'CREATE TABLE `jogos` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`casaid` varc'
at line 2
Thanks in advance.
EDIT:
Thanks Joel and Florian for explaining. I do not really know about MySQLi, anyway, a solution that did not need to use the extension. For those who need it:
$sqls = ""; // here go your all sql's
$split_sqls = explode(";", $sql);
for($index = 0; $index < count($split_sqls) - 1; $index++) {
$query = mysql_query($split_sqls[$index]);
if(!$query)
die("Error at $index SQL.\n\n".mysql_error());
}
Regards!