【问题标题】:How can i insert a single data into a Mysql table using Python?如何使用 Python 将单个数据插入到 Mysql 表中?
【发布时间】:2021-04-08 12:33:06
【问题描述】:

我已尝试此代码,但收到 1064 错误。

x_1=**********    
t_2=(x_1)
cursor.execute('insert into informations' '(password)' 'values (%s)',t_2)

【问题讨论】:

    标签: python mysql mysql-connector-python


    【解决方案1】:
    cursor.execute('insert into informations (password) values (?)', (x_1,))
    

    会是更好的语法。

    只有一个字符串,包括整个语句,并使用问号作为要插入的值的占位符。

    最重要的是将单个值定义为元组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      • 2020-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多