SQLite Syntax Error with Alter Command
I tried to execu开发者_StackOverflow中文版te a SQLite ALTER TABLE [...] RENAME TO [...]
function in PHP, but I keep running into an error: Warning: sqlite_query() [function.sqlite-query]: near "ALTER": syntax error in [file] on line 3
The code seems simple to me, and I have tried to get around the error, but so far the problem has stumped two programmers. I also get a similar error when trying to drop the table (Warning: sqlite_query() [function.sqlite-query]: near "EXISTS": syntax error in [file] on line 10
). Looking at the SQLite website, the code seems to be ok:
<?php
$db = sqlite_open("[database file]", 0666);
sqlite_query($db, "ALTER TABLE users RENAME TO old_users");
/* [...] */
sqlite_query($db, "DROP TABLE IF EXISTS old_users");
?>
Complete error page:
Warning: sqlite_query() [function.sqlite-query]: near "ALTER": syntax error in [file] on line 3
Warning: sqlite_query() [function.sqlite-query]: near "EXISTS": syntax error in [file] on line 10
Might anyone have any clue why this doesn't work?
Looking at the changelogs, it seems that :
RENAME
has been added in SQLite 3.1- and
IF EXISTS
has been added in SQLite 3.3
You are using SQLite functions -- which are for SQLite 2.
Try using the SQLite3 API, which supports SQLite 3.
精彩评论