Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
pedrotuga
Forum Contributor
Posts: 249 Joined: Tue Dec 13, 2005 11:08 pm
Post
by pedrotuga » Fri Feb 02, 2007 6:25 am
I am migrating my forums to another forum script and also from mysql to sqlite....
this code returns errors on the sqlite query line
Code: Select all
$sql_get_users ="SELECT user_id,username,`password`,email,posts,date_added FROM phorum_users WHERE active=1 AND user_id > 2";
$result_users = mysql_query($sql_get_users);
$sql_insert_users = array();
while ($row = mysql_fetch_assoc($result_users)){
$sql_insert_users[]="INSERT INTO users (id,username,password, email,num_posts,registered) VALUES
(".$row["user_id"].",".$row["username"].",".$row["password"].",".$row["email"].",".$row["posts"].",".$row["date_added"].")";
}
foreach ($sql_insert_users as $iterador){
$iterador = sqlite_escape_string($iterador);
echo $iterador."<br />";
sqlite_query ( $db, $iterador );
}
Warning: sqlite_query() [function.sqlite-query]: unrecognized token: "@" in ...
what am i missing here?
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Fri Feb 02, 2007 6:33 am
Well unless it's earlier on in your code, the @ is from "email".... I've never used sqlite before,so maybe you should check how it handles @ signs.
xinnex
Forum Commoner
Posts: 33 Joined: Sun Jan 07, 2007 7:38 pm
Location: Copenhagen, Denmark
Post
by xinnex » Fri Feb 02, 2007 6:40 am
Try adding some apostrophes around those string-values in your insert-statement..
eg:
Code: Select all
,'".$row["username"]."','".$row["password"]."','".$row["email"]."', //etc..
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Fri Feb 02, 2007 6:41 am
.... That would be the reason sqlite was looking at the literal value as a part of the query. Good eye.
pedrotuga
Forum Contributor
Posts: 249 Joined: Tue Dec 13, 2005 11:08 pm
Post
by pedrotuga » Fri Feb 02, 2007 6:55 am
xinnex wrote: Try adding some apostrophes around those string-values in your insert-statement..
eg:
Code: Select all
,'".$row["username"]."','".$row["password"]."','".$row["email"]."', //etc..
it doesnt work
it keeps trowing the exact same error...
here is my new code:
Code: Select all
while ($row = mysql_fetch_assoc($result_users)){
$sql_insert_users[]="INSERT INTO users
(id,username,password, email,num_posts,registered)
VALUES
(".$row["user_id"].",'".$row["username"]."','".$row["password"]."','".$row["email"]."',".$row["posts"].",".$row["date_added"].")";
}
mikeq
Forum Regular
Posts: 512 Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland
Post
by mikeq » Fri Feb 02, 2007 7:30 am
Why dont you output the query string to your screen so you can see what it looks like before passing it to the function that tries to execute it as a query.
pedrotuga
Forum Contributor
Posts: 249 Joined: Tue Dec 13, 2005 11:08 pm
Post
by pedrotuga » Fri Feb 02, 2007 12:18 pm
mikeq wrote: Why dont you output the query string to your screen so you can see what it looks like before passing it to the function that tries to execute it as a query.
if you check on my code i did just that. It looked ok, but then... double quotes cannot replace single ones when it comes to sql. The dummy error is that i am escaping the whole query, which doesnt make sense. I fixed it already, i should escape only the strings i will insert in the query rather then the query itself.
Thank you all for the quick help.