python 查询数据库报错不知道为啥

def search_sql(room_name):
   sql_word = "select %s from room"%(room_name)
   cur_search.execute(sql_word)
   conn_search.commit()
   result = cur_search.fetchone()
   return result
   
Traceback (most recent call last):
  File "msg_test.py", line 183, in <module>
    room_id = sqls.search_sql(room_name)
  File "../sqls.py", line 18, in search_sql
    cur_search.execute(sql_word)
  File "/usr/local/python3/lib/python3.6/site-packages/pymysql/cursors.py", line 170, in execute
    result = self._query(query)
  File "/usr/local/python3/lib/python3.6/site-packages/pymysql/cursors.py", line 328, in _query
    conn.query(q)
  File "/usr/local/python3/lib/python3.6/site-packages/pymysql/connections.py", line 517, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/usr/local/python3/lib/python3.6/site-packages/pymysql/connections.py", line 732, in _read_query_result
    result.read()
  File "/usr/local/python3/lib/python3.6/site-packages/pymysql/connections.py", line 1075, in read
    first_packet = self.connection._read_packet()
  File "/usr/local/python3/lib/python3.6/site-packages/pymysql/connections.py", line 684, in _read_packet
    packet.check_error()
  File "/usr/local/python3/lib/python3.6/site-packages/pymysql/protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "/usr/local/python3/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.ProgrammingError: (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 'from room' at line 1")
secoo_RD@client1 secoochengdu$ cd ..
阅读 1.5k
1 个回答

sql语句错误

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 'from room

检测下你的sql吧

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题