discuz做二次开发,有个bug让我头疼了2天。
由于数据的需要把post表中的pid改为bigint(20)
可是用$db->insert_id()取出来的不是刚刚插入的pid值,导致附件找不到对应的帖子
找了2天原因,后来在php手册看到:
mysql_insert_id() 将 MySQL 内部的 C API 函数 mysql_insert_id() 的返回值转换成 long(PHP 中命名为 int)。如果 AUTO_INCREMENT 的列的类型是 BIGINT,则 mysql_insert_id() 返回的值将不正确。可以在 SQL 查询中用 MySQL 内部的 SQL 函数 LAST_INSERT_ID() 来替代。
于是将db类里的 insert_id 做以下修改
<?php
function insert_id() {
//return ($id = mysql_insert_id($this->link)) >= 0 ? $id : $this->result($this->query("SELECT last_insert_id()"), 0);
return $this->result($this->query("SELECT last_insert_id()"), 0); //在bigint下使用这个语句,mysql手册中说SELECT last_insert_id()是多用户安全的
}
?>
问题解决