pymysql 操作 直接插入数据库
在 xxx.py 文件里
sql = 'INSERT INTO xxx (`a_id`, `title`, `body`) VALUES (%s, %s, %s)'
value = (tttt, tttt, tttt,)
conn.execute(sql, value)
这一句如果想得到 面上面插入数据的 ID
用下面三句
tp_id =conn.execute('select LAST_INSERT_ID();')
tp_id = conn.execute('select max(id) from xxx;')
tp_id = conn.execute('select @@identity')
上面三个语句 都是返回 执行成功的行数 也就是说 tp_id 的结果是 1 或者 0
那有什么办法 得到该记录的 id 并赋值给 tp_id ?
用 conn.lastrowid 可以。
但是不知道用 上面三条语句中的方法怎么得出这个 ID 并赋值给 tp_id ?
谢谢
在 xxx.py 文件里
sql = 'INSERT INTO xxx (`a_id`, `title`, `body`) VALUES (%s, %s, %s)'
value = (tttt, tttt, tttt,)
conn.execute(sql, value)
这一句如果想得到 面上面插入数据的 ID
用下面三句
tp_id =conn.execute('select LAST_INSERT_ID();')
tp_id = conn.execute('select max(id) from xxx;')
tp_id = conn.execute('select @@identity')
上面三个语句 都是返回 执行成功的行数 也就是说 tp_id 的结果是 1 或者 0
那有什么办法 得到该记录的 id 并赋值给 tp_id ?
用 conn.lastrowid 可以。
但是不知道用 上面三条语句中的方法怎么得出这个 ID 并赋值给 tp_id ?
谢谢