mysql select 報錯

代碼片斷:html

     sql_url = "select * from webpage where url = '%s'" % b
     
     try:
         cursor.execute(sql_url)
         results = cursor.fetchall()
     except Exception, e:
         print e
         pass


系統:centospython

語言:pythonweb

報錯信息:sql

(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 '''' at line 1")

 

報錯信息說 在‘「'附近有語法錯誤,centos

可是大部分數據都很順利的跑起來,而後我把錯誤時候的那條數據給打印出來,發現那個url後面有 xxx='xxxxxxxx'fetch

因此把這個url塞進sql語句,就成了 select * from webpage where url ='http://www.baidu.com/index.html?xxx='xxxxxxxxx''url

哈哈,看出來了吧?spa

那個參數的後單引號和url的後單引號合併在一塊兒了,原本是2個的,結果成1個了。code

 

正確的寫法是:server

sql_url = 'select * from webpage where url = "%s"' % b
相關文章
相關標籤/搜索