How to modify a column present in a mysql database through python? -


i'm able connect database. want change values present in particular column.

cursor.execute("select * foo;") rows = cursor.fetchall() row in rows:     print(row) 

output of above code is,

('foo,bar,foo,bar',) ('foobar,bar',) ('foo,bar,buz,buz',) 

i'm able replace value by,

rows = cursor.fetchall() row in rows:     print(re.sub(r'^[^,]*,', '', row[0])) cursor.close() 

returns,

bar,foo,bar bar bar,buz,buz 

but don't know how setback altered string particular column.

i think need use update query, tried

for row in rows:     cursor.execute("update foo set  categories=%s;", re.sub(r'^[^,]*,', '', row[0])) 

but returns error message of,

you have error in sql syntax; check manual corresponds mysql server version right syntax use near '%s' @ line 1 

as said in comment need specify column id query :

for row in rows:         sub=re.sub(r'^[^,]*,', '', row[0])         cursor.execute("update drug_specifications set  categories=%s id=%s;",(sub, str(row[0]))) 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -