python - How to pass a variable to a mysql query? -


this 1 has no errors

cursor.execute ("update `1` set `2`='aaa' `1`='5'") 

this 1 has errors.

cursor.execute ("update `1` set `2`=aaa `1`='5'") 

the difference is, trying pass variable 'aaa' it.

here error_log of apache

[tue may 14 21:20:24 2013] [error] [client 127.0.0.1] operationalerror: (1054, "unknown column 'aaa' in 'field list'")

in php type $aaa in mysql query, assumption in python type aaa.

if trying pass value of variable, need write "aaa" outside string. so, instead of:

cursor.execute ("update `1` set `2`=aaa `1`='5'") 

try:

cursor.execute ("update `1` set `2`= '" + aaa + "' `1`='5'") 

just aware that, if using python, may need convert variable string (if holds number example), using:

str(aaa) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -