What's wrong with this ?
I have a set of SQL query inside .sql file. and php code to runs it.
PHP code that runs it.
PHP Code:
$fp = fopen('schema/mysql.sql', 'r');
$schema = fread($fp, filesize('schema/mysql.sql'));
fclose($fp);
$sqls = explode("\n", $schema);
foreach ($sqls as $sql)
{
$pos = strpos($sql, 'phpdesk_');
$table = substr($sql, $pos);
$pos = strpos($table, '`');
$table = substr($table, 0, $pos);
if($db->query($sql))
{
if ( preg_match("/CREATE TABLE (\S+) \(/", $sql ))
{
echo 'Table Created Successfully: '.$table."<br />\n";
}
}
else
{
echo 'Cannot Create Table: '.$table."<br />\n";
}
}
SQL Query
sql Code:
DROP TABLE IF EXISTS `phpdesk_admin`
CREATE TABLE `phpdesk_admin` (
`id` int(255) NOT NULL DEFAULT '0',
`name` varchar(255) NOT NULL DEFAULT '',
`pass` varchar(255) NOT NULL DEFAULT '',
`email` varchar(255) NOT NULL DEFAULT '',
`notify_pm` int(1) NOT NULL DEFAULT '1',
`notify_response` int(1) NOT NULL DEFAULT '1',
`notify_ticket` int(1) NOT NULL DEFAULT '1',
`tppage` int(255) NOT NULL DEFAULT '25',
`signature` mediumtext NOT NULL,
PRIMARY KEY (`id`)
)
It gives me this error.
Code:
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 '' at line 1Cannot Create Table: phpdesk_admin
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 '`id` int(255) NOT NULL default '0',' at line 1Cannot Create Table:
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 '`name` varchar(255) NOT NULL default '',' at line 1Cannot Create Table:
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 '`pass` varchar(255) NOT NULL default '',' at line 1Cannot Create Table:
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 '`email` varchar(255) NOT NULL default '',' at line 1Cannot Create Table:
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 '`notify_pm` int(1) NOT NULL default '1',' at line 1Cannot Create Table:
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 '`notify_response` int(1) NOT NULL default '1',' at line 1Cannot Create Table:
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 '`notify_ticket` int(1) NOT NULL default '1',' at line 1Cannot Create Table:
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 '`tppage` int(255) NOT NULL default '25',' at line 1Cannot Create Table:
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 '`signature` mediumtext NOT NULL,' at line 1Cannot Create Table:
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 'PRIMARY KEY (`id`)' at line 1Cannot Create Table: PRIMARY KEY (
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 ')' at line 1Cannot Create Table:
I copied the query over to phpmyadmin and run it without any problem.
However, this query doesn't looks like there's problem.
sql Code:
DROP TABLE IF EXISTS `phpdesk_admin`
CREATE TABLE `phpdesk_admin` (
`id` int(255) NOT NULL DEFAULT '0',
`name` varchar(255) NOT NULL DEFAULT '',
`pass` varchar(255) NOT NULL DEFAULT '',
`email` varchar(255) NOT NULL DEFAULT '',
`notify_pm` int(1) NOT NULL DEFAULT '1',
`notify_response` int(1) NOT NULL DEFAULT '1',
`notify_ticket` int(1) NOT NULL DEFAULT '1',
`tppage` int(255) NOT NULL DEFAULT '25',
`signature` mediumtext NOT NULL,
PRIMARY KEY (`id`))
It's just one of the query in the sql file. The latter SQL query file works, but it's outdated. Thus, I used another updated SQL file, which is the former. And it doesn't allows me to create.
Any idea?