Python MySQL Parameterized Queries -


i having hard time using mysqldb module insert information database. need insert 6 variables table.

cursor.execute ("""     insert songs (songname, songartist, songalbum, songgenre, songlength, songlocation)     values         (var1, var2, var3, var4, var5, var6)  """) 

can me syntax here?

beware of using string interpolation sql queries, since won't escape input parameters correctly , leave application open sql injection vulnerabilities. the difference might seem trivial, in reality it's huge.

incorrect (with security issues)

c.execute("select * foo bar = %s , baz = %s" % (param1, param2)) 

correct (with escaping)

c.execute("select * foo bar = %s , baz = %s", (param1, param2)) 

it adds confusion modifiers used bind parameters in sql statement varies between different db api implementations , mysql client library uses printf style syntax instead of more commonly accepted '?' marker (used eg. python-sqlite).


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -