Skip to content Skip to sidebar Skip to footer

What Does The %s Placeholder Stand For?

I am learning to use MySQL Connector/Python. In most of the tutorials, I see they use the %s placeholder inside VALUES clause for inserting data in a table. Then, on the next line,

Solution 1:

It tells the string that the value will be converted to a string and replace the placeholder at that position.

But the connector also supports prepared statements.

cursor = connection.cursor(prepared=True)
sql_insert_query = """ INSERT INTO customers (name, address) VALUES (%s, %s)"""

insert_tuple_1 = ("Json", "BAker street")
insert_tuple_2 = ("Emma", "Avenue des Champs-Élysées")

cursor.execute(sql_insert_query, insert_tuple_1)
cursor.execute(sql_insert_query, insert_tuple_2)
connection.commit()

Post a Comment for "What Does The %s Placeholder Stand For?"