Interworking with Python data values in Python pimysql

Asked 1 years ago, Updated 1 years ago, 95 views

When you have a table called X in the Workbench (in which you have columns called value1, value2) and you define a list called A=[1,2,3] in Python, what should I do with this Python mysql code? For example, the Value column of X has the same value as A[2] "Select X.value2 where X.value1=A[2]" I want to write a code with this meaning.

pymysql python

2022-09-21 11:10

1 Answers

import pymysql
a = [1,2,3]
db = pymysql.connect(host='', port=3306, user='',passwd='', db='', charset='utf8')
cur = db.cursor()
sql = "select value2 from Table where value1=%s"
cur.execute(sql,(a[2]))
r = cursor.fatchall()
for i in r:
    print(i)

There are many use cases of pymysql on Google.


2022-09-21 11:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.