4

Does PyMySQL support prepared statements? I am trying to connect to MySQL from a python module.

I have checked documentation at http://pymysql.readthedocs.io and didn't find anything useful.

No luck on skimming the source code either.

Brindha
  • 329
  • 5
  • 16

3 Answers3

3

PyMySQL does not support prepared statements yet. See PyMySQL issue 202

Chirag Maliwal
  • 426
  • 10
  • 22
Daniel Milde
  • 986
  • 1
  • 10
  • 15
0

No support for Prepared Statements will ever come to PyMySQL, I guess. Use Oracle's MySQL Connector for this. https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursorprepared.html

akamac
  • 31
  • 3
-2

The above answer is outdated: PyMySQL does now support prepared statements:

cur = con.cursor()

cur.execute("SELECT * FROM cities WHERE id=%s", myid) 

cid, name, population  = cur.fetchone()

Regards!

sdsc81
  • 550
  • 8
  • 17
  • 3
    WARNING: THIS IS WRONG. This does not use mysql prepared-statements, but rather it is native python string formatting. (i looked in the source code) – thelogix Feb 02 '21 at 14:16