Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

MySQL error #1064

mysql

  • Please log in to reply
8 replies to this topic

#1 zeroradius

zeroradius

    Speaks fluent binary

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1085 posts

Posted 01 October 2012 - 01:15 PM

Ok so I am having a problem with a row in my mail table. The problem is I can't select it? I originally had it set as a tinyInt but changed it to just int but that did not help anything. I am running the query directly from PhpMyAdmin. I can select other cells in the row I want just not the read cell.

I ran the following test queries for troubleshooting

  • SELECT * FROM mail WHERE id = 1
  • SELECT * FROM mail WHERE to_id = 6
  • SELECT * FROM mail WHERE read = 0


The results:

  • Worked
  • Worked
  • #1064 - 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 'read = 0 LIMIT 0, 30' at line 1


Here is my data structure
Posted Image

Here is my Data
Posted Image

Thanks in advance
~ Zero
  • 0
Posted Image

#2 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 01 October 2012 - 01:25 PM

Try a column name other than 'READ'. The reserved word 'READ' is used in table locking statements.
  • 1

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3 zeroradius

zeroradius

    Speaks fluent binary

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1085 posts

Posted 01 October 2012 - 01:33 PM

That worked. Din't even think of reserved words. Thanks
  • 0
Posted Image

#4 VNFox

VNFox

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 648 posts
  • Programming Language:C#, PHP
  • Learning:Assembly

Posted 01 October 2012 - 01:43 PM

I think you can do this:

SELECT * FROM mail WHERE `read` = 0

This will works ... if you want to pull it as read.
  • 0

www.pickmike.com
I don't just develop software. I find solutions to your business needs.


#5 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 01 October 2012 - 01:45 PM

I think you can do this:

SELECT * FROM mail WHERE `read` = 0

This will works ... if you want to pull it as read.


I think it's best practice to avoid reserved words in your column names, or else it could create problems for other programmers who have to work on your code.
  • 1

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#6 VNFox

VNFox

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 648 posts
  • Programming Language:C#, PHP
  • Learning:Assembly

Posted 01 October 2012 - 01:59 PM

For me i think it's best to escape column names ... for example with MSAccess or SQL then use [columnName] use [ ], MySQL use ` ` to escape your column names. I don't think t hat we know all the reserve words for all databases ... so it's best to escape them.
  • 0

www.pickmike.com
I don't just develop software. I find solutions to your business needs.


#7 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 01 October 2012 - 05:08 PM

For me i think it's best to escape column names ... for example with MSAccess or SQL then use [columnName] use [ ], MySQL use ` ` to escape your column names. I don't think t hat we know all the reserve words for all databases ... so it's best to escape them.

I'll go with VNFox -- it is better (at least for me) to use escaping character rather than knowing all the reserved words.
  • 0

#8 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 01 October 2012 - 10:14 PM

I would do both. Avoid reserved words AND escape them.
http://dev.mysql.com...rved-words.html
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#9 Colanth

Colanth

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 165 posts
  • Location:Fayetteville, NC, USA
  • Programming Language:PHP, (Visual) Basic, JavaScript, Visual Basic .NET, Pascal, Logo, Assembly, VBScript, Others

Posted 03 November 2012 - 02:56 PM

If you avoid them, Orjan, you don't have to escape them. And avcoiding them is better.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download