我正在嘗試更新MySQL DB中的數(shù)據(jù),但它拋出錯(cuò)誤:UPDATE scrapedDataTable SET productDesc=, moreProductImages=full/545521_1363869251%20copy-500x500.jpg,full/545521_1363869251%20copy-275x275.jpg,full/545522_1363869309%20copy-500x500.jpg,full/545522_1363869309%20copy-74x74.jpg, ,productCategory=Clothing, productSubCategory=NA WHERE Server=http://1click1call.com/Jeans-Shirts-Tshirts-Trousers/W-for-Woman-Kurta-54552And error:(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'moreProductImages=full/545521_1363869251%20copy-500x500.jpg,full/545521_13638692' at line 1")"(<class '_mysql_exceptions.ProgrammingError'>)"我的表結(jié)構(gòu)是:+--------------------+---------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+--------------------+---------------+------+-----+---------+-------+| productTitle | varchar(100) | NO | | NULL | || productSite | varchar(1000) | NO | | NULL | || productDesc | text | YES | | NULL | || productURL | varchar(325) | NO | PRI | NULL | || productMRP | varchar(200) | YES | | NULL | || productPrice | varchar(200) | YES | | NULL | || productCategory | varchar(50) | YES | | NULL | || productSubCategory | varchar(50) | YES | | NULL | || imageURL | text | YES | | NULL | || moreProductImages | text | YES | | NULL | |+--------------------+---------------+------+-----+---------+-------+詢問 :cursor.execute("UPDATE scrapedDataTable SET productDesc=%s,moreProductImages='%s', ,productCategory=%s, productSubCategory=%s WHERE productURL=%s" %(productDesc,image_paths,productCategory,productSubCategory,productURL))誰能幫我...
2 回答

jeck貓
TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊
由所有Python SQL庫實(shí)現(xiàn)的Python數(shù)據(jù)庫API使用已參數(shù)化的查詢-本手冊(cè)中沒有涉及到PHP中常見的無用的參數(shù)廢話轉(zhuǎn)義。您需要%s
在查詢中的s周圍舍棄單引號(hào),而不是使用%
運(yùn)算符手動(dòng)(且容易注入)將參數(shù)格式化為查詢格式,而%
用逗號(hào)替換,
以將參數(shù)作為第二個(gè)參數(shù)傳遞給execute()
。
添加回答
舉報(bào)
0/150
提交
取消