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?
Related
I am trying to update database in mysql but when i use the query in mysql it works perfectly fine......but when i update it through jsp it gives me an error as
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 ')' at line 1
this is query of JSP: (in content i do not add any closing brackets like ')')
insert into location_"+username+"
values('"+coordinates+"','"+content+"',"+latitude+","+longitude+");
i use stmt.executeUpdate(q1);
the above query is stored in q1..
this is query in mysql:(this works absolutely fine)
insert into location_user1 values('{lat: 19.2222, lng: 73.9781}','random coordinate from database', 19.2222, 73.9781);
i have found out that this error is somewhat common..yet i could not find out any solution...PLease Help!! Thank You!! This error is so frustrating..
Try printing q1 and execute the printed output in MySQL.
At jsp end, the query is not getting properly built and this only is leading to the issue.
I am working on a simple program and attempting to pull some information out of a database. The table within the database that I am using is called names. If I do something like this:
self.cursor.execute("""select * from names WHERE first_name = 'Sarah' """)
for row in self.cursor.fetchall():
print(row[0])
I get exactly what I want. But if I change that name to a variable like and do something like:
name = input('Enter First name: ')
self.cursor.execute("""select * from names WHERE first_name=%s""", (name))
I get the following error: mysql.connector.errors.ProgrammingError: 1064 (42000): 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 '%s' at line 1
I know that there are other posts on this site close to my question and what I have tried from them does not seem to work. I have also tried following some tutorials and still get this error. So any help would be appreciated! Thank you! I am using mysql.connector, Python 3.4 and Flask.
Okay I found the answer myself. I had to do this: self.cursor.execute(query, (name,)) and the answer was found digging deeper and I found this site: Python MySQL Connector database query with %s fails
Seems to be strange but very simple SQL query doesn't work for me.
UPDATE wp_postmeta SET `meta_value` = REPLACE(post_meta, `http://url/`, `http://new_url`)
Error message appears 'a new statement was found but no delimiter was found between it and the previous one (REPLACE) and when I'm trying to execute the code - #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 ')' at line 1. Please advise.
Your specific issue is the use of backticks rather than single quotes. However, I think a better way to express the logic is:
UPDATE wp_postmeta
SET meta_value = CONCAT('http://new_url', SUBSTRING(post_meta, 12) )
WHERE meta_value LIKE 'http://url/%' AND
meta_key = ??;
This uses the WHERE clause to filter out rows that should not be updated. It also ensures that the update is only to the occurrence of 'http://url/' at the beginning the string -- usually the logic that is intended.
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;
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';