Archive for March, 2009

mysql #1064

March 2, 2009 Leave a comment

Today evening I was as usual coding something and the code which I had written had ->
$q1="INSERT into table_name(name,time,desc) VALUES('$name','$time','$desc')";

The code just refused to do what it was supposed to. Yeah you might have figured that out.
Some learnings from this were – First thing you should do when things don’t work in mysql is echo the query and try running it in phpmyadmin or at the prompt!
I have been using mysql for like 1.1/2 years now and I come across this outlandish error. Almost eccentric and I tried looking at he code again and again to check if i misspelt something or missed a comma, whatever….Good that there weren’t any mistakes there, bad it took too much time. I slept for 2 hours very frustrated !! Then I went to phpmyadmin. and there I see the “ERROR” – #1064

At once googled and there I see the answer to my problems – reserved words.
Mysql has reserved words ! Some words cannot be used as identifiers directly and to use them all we need to do is quote them.
Query: INSERT into table_name(name,`time`) VALUES('abcd','23443545')
The identifier quote character is the backtick (“`”). TIME is a reserved word. Check out Schema object names

huh…another life’s problem solved!

%d bloggers like this: