tanxin
tanxin

Reputation: 11

Python MySQL insert into with parameter

I am having a hard time using the MySQLdb module to insert information into my database. I need to insert 2 variables into the table.My table is userid,the type of user_id is varchar,the type of count is int.

  SQL = 'select user_id,count(*)AS num from client1 group by user_id order by count(*) desc;'
  for row in cursor.execute(SQL):
       a = row.user_id
       b = row.num
       cursormysql.execute("insert into userid(user_id,count) VALUES (%s,%s))",(a,b))
       db.commit()

Upvotes: 0

Views: 1675

Answers (1)

zambesianus
zambesianus

Reputation: 1249

Your parenthesis do not match on cursormysql.execute("insert into userid(user_id,count) VALUES (%s,%s))",(a,b))

Try like cursormysql.execute("insert into userid(user_id,count) VALUES (%s,%s)",(a,b))

Upvotes: 1

Related Questions