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
https://forums.phpfreaks.com/topic/98781-query-error/
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
https://forums.phpfreaks.com/topic/98781-query-error/#findComment-506126
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
https://forums.phpfreaks.com/topic/98781-query-error/#findComment-506156
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
https://forums.phpfreaks.com/topic/98781-query-error/#findComment-506461
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.