简单的说,目标就是获取数据库表中的下一个auto_id sequence.
先看了这篇文章: http://blog.jamiedoris.com/geek/560/。在MySQL中使用
我用的PostgreSQL8, Google了下,找到了一个pg下类似的方法:
但出现错误:currval of sequence is not yet defined in this session
currval只能在执行 NEXTVAL 后执行。解决方法是使用
先看了这篇文章: http://blog.jamiedoris.com/geek/560/。在MySQL中使用
"SHOW TABLE STATUS LIKE '$tablename'";
我用的PostgreSQL8, Google了下,找到了一个pg下类似的方法:
select currval(pg_get_serial_sequence(tablename, id_seq))
但出现错误:currval of sequence is not yet defined in this session
currval只能在执行 NEXTVAL 后执行。解决方法是使用
select last_value from seq
但最后又有一个小问题,新建立的数据库,返回的last_value是1;而添加成功一个后,第二个返回的也是1,添加不成功。用了比较土的方法规避了下。