sql = "INSERT IGNORE INTO users_time_zone (user_id, email, username, gcm_reg_id, time_zone) " \
"VALUES(%s, '%s', '%s', '%s', '%s') ON DUPLICATE KEY UPDATE gcm_reg_id ='%s', id=LAST_INSERT_ID(id) " % \
(user_data['user_id'], user_data['email'], user_data['username'],
user_data['gcm_reg_id'], user_data['time_zone'], user_data['gcm_reg_id'])
print sql
cursor = conn.cursor()
cursor.execute(sql)
conn.commit()
some times username is like dinda_a'yunin or dinda_a"yunin which makes sql like this
INSERT IGNORE INTO users_time_zone (user_id, email, username, gcm_reg_id, time_zone) VALUES(4298849, 'dinda_a'yunin@yahoo.com', 'dinda_ayunin', 'APA91bGRvg74', 'Asia/Jakarta') ON DUPLICATE KEY UPDATE gcm_reg_id ='APA91bGRvg74', id=LAST_INSERT_ID(id)
That makes wrong syntax is there anyway to solve that