Quantcast
Channel: MySQL Forums - InnoDB
Viewing all articles
Browse latest Browse all 1957

What is wrong with my syntax? (Error 1064) (2 replies)

$
0
0
Hello all, I have a bit of a problem that makes no sense to me. I am using PHP to work with a MySQL database using the InnoDB engine in three different ways:

1. I use the following code to reset my database completely:
<< CODE >>
mysql_query("DROP DATABASE IF EXISTS `" . $db_name . "`");
$result = mysql_query("CREATE DATABASE `" . $db_name . "`");
if (!$result) return $result;

$result = mysql_select_db($db_name);
if (!$result) return $result;

$result = mysql_query("CREATE TABLE `site` (
`key` VARCHAR(20) NOT NULL,
`value` VARCHAR(20),
INDEX (`key`)
);");
if (!$result) return $result;
<< CODE >>

This works fine.

2. I have a function to upgrade my database structure, which modifies the existing database in arbitrary ways. In this case I have code similar to the above that tries to execute the following SQL:

<< CODE >>
START TRANSACTION;
DROP TABLE `site`;
CREATE TABLE `site` (
`key` VARCHAR(20) NOT NULL,
`value` VARCHAR(20),
PRIMARY KEY (`key`)
);
COMMIT;
<< CODE >>

This gives me error 1064 (You have an error in your MySQL Syntax...) on line 2, the DROP TABLE line. I can't see how I have done that wrong, but okay..

3. Finally I have a backup function that dumps the database to an SQL file, and I load it in with the following code:

$result = mysql_query(file_get_contents($backups[$_GET['id']]['filename']));

From an automatically generated file containing this:
<< CODE >>
DROP TABLE site;

CREATE TABLE `site` (
`key` varchar(20) NOT NULL,
`value` varchar(20) DEFAULT NULL,
KEY `key` (`key`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO site VALUES("db_version","3");
INSERT INTO site VALUES("last_update","1332868011");
<< CODE >>

Which also gives me error 1064, except on line 3, the CREATE TABLE line.

I am completely baffled, so if anyone can offer me some advice it would be much appreciated! Thanks.

Viewing all articles
Browse latest Browse all 1957

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>