SImple MySQL update not working with generic error - mysql

I have never had this happened to me before, it is very very strange,
very simple SQL update is not working:
UPDATE table givi_user_sessions set givi_user_clientid='somevalue' where givi_user_id=2;
i tried other variations like:
UPDATE table givi_user_sessions set where givi_user_id=3 where givi_user_id=2
and this too:
UPDATE table `givi_user_sessions` set where `givi_user_id`=3 where `givi_user_id`=2
All those options gave me following error:
Error : 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 'table givi_user_sessions set givi_user_clientid='somevalue' where givi_user_id=2' at line 1
I double checked that table exists, and also that column names are correct,
the only thing that I can recall is that i changed table name from user_sessions to givi_user_sessions, but that should not matter at all, unless something got messed in mysql engine, because I definately think that my sql is correct. or maybe i have been working for too long today.
any advices would be appreciated.

You don't need to include the keyword "table" in your query. You can check the syntax of the update query here: http://www.w3schools.com/php/php_mysql_update.asp
It should look like this:
UPDATE givi_user_sessions set givi_user_clientid='somevalue' where givi_user_id=2;

Related

MySQL find and replace not working as expected (serialized data)

Im trying to create a MySQL search and replace script for my wp_postmeta db table.
I need to search this fields that are similar to this.
a:2:{i:0;a:3:{s:4:"name";s:15:"Personalisation";s:4:"type";s:7:"heading";s:11:"description";s:0:"";}i:1;a:13:{s:4:"name";s:8:"Initials";s:12:"title_format";s:5:"label";s:4:"type";s:11:"custom_text";s:17:"restrictions_type";s:8:"any_text";s:11:"description";s:0:"";s:18:"description_enable";i:0;s:8:"required";i:1;s:3:"min";s:1:"1";s:3:"max";s:1:"4";s:12:"restrictions";i:1;s:5:"price";s:1:"3";s:10:"price_type";s:14:"quantity_based";s:12:"adjust_price";i:1;}}
and replace the "required";i:1; with "required";i:0;
Im using phpmyadmin to create and run the script but so far I cannot get what I have written to run with the semicolons in there.
This is what ive come up with so far;
UPDATE wp_postmeta
SET meta_value = replace(meta_value, '"required";i:1;', '"required";i:0;')
WHERE meta_key = '_product_addons';
and get the error (removing the semicolons fixes this but then doesn't match anything):
#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 ''"required")' at line 1
I've tried using \ to escape them and this doesn't work, this is about as far as my knowledge goes with MySQL so hoping someone can help?
Thanks
OK so I've found out that this actually works fine but won't work when using the Simulate option, can anyone explain why this is?

mysql: Not able to create a table

create table 5390e910_abb3_40e2_bdfa_bd9d369e6dc6 like sample_table
is failing.
ERROR: #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 '5390e910_abb3_40e2_bdfa_bd9d369e6dc6 like
notification_sample_history' at line 1
Now I don't see any flaw with the above name as the mysql documentation says:
64 characters max
can start with any alphabet/digit
an contain underscores/alphabets/digits
Though I am able to run something like this:
create table 1f8b784f_f580_4a82_9e93_167a2d9c79f5 like sample_table
I believe it's the first "e". When I swap that character for any other letter, the query works just fine.
I'm not positive on this, but my suspicion is that MySQL is reading your string and considering it to mean the number "5,390 times 10 to the power of 910abb3[etc]". And while all-numeric table names are valid they must be quoted.
Try enclosing your table name in back-ticks. This works for me:
create table `5390e910_abb3_40e2_bdfa_bd9d369e6dc6` like abbreviations;

Correct format to use regex in MySQL SELECT statement (not within WHERE section)

I need to use REGEX (or similar functiuonality) to update an existing table in order to identify if a string field contains a correctly formatted code:
UPDATE tblRequests SET flagIsRefCodeOK=(RefCode REGEX '^[A-Z0-9]{8}-(?:[A-Z0-9]{4}-){3}[A-Z0-9]{12}$') WHERE DataSetID=11
But it doesn't seem to like the statement:
#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 'REGEX '^[A-Z0-9]
Note, this code will be added to a BEFORE INSERT trigger, which is responsible for updating a number of flags. I'm not fussed (much) with whether the REGEX is correct, especially within MySQL, I just want it to try to work. Then I'll figure out the exact REGEX if this doesn't work.
Thnx
The operator name is REGEXP not REGEX, so try:
UPDATE tblRequests
SET flagIsRefCodeOK= (RefCode REGEXP '^[A-Z0-9]{8}-(?:[A-Z0-9]{4}-){3}[A-Z0-9]{12}$')
WHERE DataSetID=11;

MySQL query sanity check, for update query

I have this query
update user_remember_me set
when='2012-07-06 05:44:27',
hash='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7'
where user = '21';
and I am getting this error
Error : 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 'when='2012-07-06 05:44:27', hash='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7' wher' at line 1
Im failing to miss the connection here, I've used simple updates like this everywhere without issue til this, maybe Im getting to tired, but this is gonna drive me nuts til I have an answer
When is a key word in mysql, change the column name
or you can use it as
`when`='2012-07-06 05:44:27'
when is a reserved word in mysql
update user_remember_me set
`when`='2012-07-06 05:44:27',
`hash`='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7'
where user = '21';
So you must backtick your column
when is a keyword within MySQL. You have to escape it, if you want to use it as a column identifier (as you should with all column identifiers!):
UPDATE user_remember_me
SET
`when`='2012-07-06 05:44:27',
`hash`='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7'
WHERE `user` = '21';

Basic MySQL Error using UPDATE query

I have no idea what I've done wrong, I've tried a lot of different things so far, reworking the statement, etc, but nothing seems to work.
I'm getting this error:
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 'SET content='this is content', active='1' WHERE id='1'' at line 1
And this is the query I'm using:
UPDATE Pages SET title='$title', SET content='$content', active='$active'
WHERE id='$id'
I've checked to make sure that it's not what's being inserted that is the problem.
Delete the second SET into your query.
You have:
SET title='$title', SET content='$content'