[英]How to concatenate int with string. then insert into mysql?
我必須插入數據。 數據由 int 和 string 組成。 我得到錯誤檢查與您的 MariaDB 服務器版本相對應的手冊以獲取正確的語法。 row[0] 是 int 字段數據類型。 如果我刪除 str function。 我只能將str(不是“int”)連接到str
cursor.execute("INSERT INTO sms_log (member_id, recipient, message, status) VALUES (" + str(row[0]) + ',' + str(row[1]) + ',' + str(row[2]) + ', Success'")")
桌子
CREATE TABLE IF NOT EXISTS `sms_log` (
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`member_id` INT NOT NULL,
`recipient` VARCHAR(255) NOT NULL,
`message` TEXT NOT NULL,
`status` VARCHAR(255) NOT NULL,
`sent_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
)ENGINE=MyISAM;
如何插入 mysql 或將 variabel int 傳遞給雙引號?
嘗試:
cursor.execute("INSERT INTO sms_log(member_id, recipient, message, status) VALUES (%s,%s,%s,%s);", (row[0],row[1],row[2],"Success"))
這樣,您將其留給 Python 以轉換為數據庫中的適當數據類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.