The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Query syntax error help
I'm attempting to copy the subscribethread table to a new table called unsub_subscribethread. Once the table is created I need to copy the data from subscribethread to unsub_subscribethread. I'm still a novice with sql but what I have looks right to me, but both queries give a syntax error
Code:
$db->query_write("CREATE TABLE IF NOT EXISTS " . TABLE_PREFIX . "unsub_subscribethread LIKE subscribethread"); Code:
$db->query_write("INSERT " . " unsub_sunscribethread SELECT * FROM subscribethread "); |
#2
|
||||
|
||||
Your query should be:
$db->query_write("CREATE TABLE IF NOT EXISTS " . TABLE_PREFIX . "unsub_subscribethread LIKE" .TABLE_PREFIX."subscribethread"); |
#3
|
|||
|
|||
If you're using a table prefix, the second query also needs TABLE_PREFIX in there (twice, once for each table name).
|
#4
|
|||
|
|||
Ah thanks guys I didn't know I needed TABLE_PREFIX again, assumed it was taken care of the first time
--------------- Added [DATE]1344207241[/DATE] at [TIME]1344207241[/TIME] --------------- Quick question, does it matter if the . has a space before and after TABLE_PREFIX? Reason I ask is Simon's query has them without spaces in the 2nd part of the query. |
#5
|
||||
|
||||
There's a space before but not after, this is because you want things similar to this
LIKE mytableprefix_subscribethread otherwise it would look like this and fail LIKE mytableprefix_ subscribethread or this LIKEmytableprefix_subscribethread |
#6
|
|||
|
|||
I still don't understand why it's different in the creating part. In the creating portion of the query it's dot space table_prefix space dot space quotation. Why isn't it dot table_prefix dot quotation?
The online tutorials (at least the ones I have checked) don't even use the same punctuations. In some they use the comma and in others they use the period. Some say you don't need the semi-colon, others say you do. Some use quotation marks around text while others use single quotation marks. How the hell do you know which one is right? |
#7
|
||||
|
||||
i think you're getting confused because vbulletin has done it's trick of adding a space after x amount of characters, here it is in quotes
Quote:
So, in a nutshell the one in the quote in this post is correct if you dont wnt to introduce any other anomalies. |
#8
|
|||
|
|||
Quote:
Code:
"The table prefix is " . TABLE_PREFIX . " for sql queries" and "The table prefix is ".TABLE_PREFIX." for sql queries" Quote:
As for the semicolon, that's used to end an sql query but it isn't needed when doing queries using the vb functions. One string has to equal exactly one query, so there's no need for an end character. In php you can use either single or double quotes. There are some differences (you should look at the php docs if you're interested), but in a lot of cases either one will work. If you're talking about use of quotes in the sql query itself, they are optional in some cases and in some cases they need to be back ticks (which can be confused with single quotes). Most likely the only thing you have to worry about (as far as valid sql) is putting single quotes around literal strings. Having said all that, a couple of the queries posted above *are* missing a space - there needs to be a space before inserting the table prefix but not after, as Simon explained, but the query above is missing a space after LIKE. I hope this helps - I'm afraid it might just be more confusing. |
#9
|
||||
|
||||
Quote:
|
#10
|
|||
|
|||
Quote:
Code:
$db->query_write("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."unsub_subscribethread LIKE ".TABLE_PREFIX."subscribethread"); Code:
$db->query_write("CREATE TABLE IF NOT EXISTS " .TABLE_PREFIX."unsub_subscribethread LIKE ".TABLE_PREFIX."subscribethread"); |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|