1、普通傳遞參數。輸入以下代碼:conn=MySQLdb.connect(user=root,passwd=123456,host=192.168.101.23,db=cmdb)。orange_id=98。sql=select×fromorangewhereid=%s%orange_id。cursor=conn.cursor(sql)。cursor.execute()。
2、使用字典dict類型傳遞參數。輸入以下代碼:sql=select×fromorangewhere%(color)s,%(weight)s。values={color:yellow,weight:30}。cursor.execute(sql,values)。