I have to insert a data. the data consist of int and string. i get error check the manual that corresponds to your MariaDB server version for the right syntax . row[0] is int field data type. if i remove str function. i get can only concatenate str (not "int") to str
cursor.execute("INSERT INTO sms_log (member_id, recipient, message, status) VALUES (" + str(row[0]) + ',' + str(row[1]) + ',' + str(row[2]) + ', Success'")")
TABLE
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;
How to insert to mysql or to pass variabel int into double quote?
Try:
cursor.execute("INSERT INTO sms_log(member_id, recipient, message, status) VALUES (%s,%s,%s,%s);", (row[0],row[1],row[2],"Success"))
This way you leave it to Python to convert to the appropriate datatype in your database.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.