Jump to content

Query Error


haku

Recommended Posts

I'm having a problem with the following query:

 

SELECT seminars, uploads, full_access FROM authorization WHERE user_id='103' LIMIT 1

 

I get the following error:

 

Database query failed: 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 'FROM authorization WHERE user_id='103' LIMIT 1' at line 1

 

I'm having a stupid moment, because I keep looking at that query, and it keeps looking entirely fine to me. Can someone else maybe point out what is wrong with it?

Link to comment
Share on other sites

Zenag: thanks for your help, but using * when retrieving data from the database is *not* a recommended technique. Its overkill - you are pulling every column out of a table, rather than just the ones you need. I suggest you look at my original query to see the proper way of doing it.

 

Uniflare: Thanks for your help as well. The quotes around column names are not necessary, and in fact I didn't end up using them.

 

In the end, my problem was my own stupidity (end of a long day of work - brain was

shutting down). The query I posted was entirely right, which is why I was so confused. I was just having a stupid moment - the query I posted wasn't the one generating the error  ::).

 

 

Link to comment
Share on other sites

Zenag: thanks for your help, but using * when retrieving data from the database is *not* a recommended technique. Its overkill - you are pulling every column out of a table, rather than just the ones you need. I suggest you look at my original query to see the proper way of doing it.

 

This is VERY true and I see too many new devs writing queries like this.

 

Even if selecting every col, it's better to do

 

SELECT `col1`, `col2`, `col3`.... ect.

 

Because SELECT * requires the db to grab the list of columns and THEN perform the query.

Link to comment
Share on other sites

thanks for that info disco and haku :). i needed every column in my request i dint know it would cause such an overhead ;)

 

the backticksare useful for compatibility, i'm sure new and old version have different "key" words, so using backticks would prevent mysql from giving an error ;) - this is what i have learned as i have made many queries which worked on one bit not the other when i did not use backticks :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.