我有以下代码:
public function createNewGuide($userID,$guideName)
{
$sql =" INSERT INTO myTable(name, updated)
VALUES ('$guideName', 'NOW()')";
//Process query
$this->query($sql); // This inserts the new row
$this->query('LAST_INSERT_ID()'); // This throws an error
return $this->query_result;
}
我的查询函数如下所示:
private function query($sql)
{
$this->query_result = mysql_query($sql, $this->conn)
or die("Unable to query local database <b>". mysql_error()."</b><br>$sql");
}
我收到以下错误:
MySQL Database Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LAST_INSERT_ID()'
我用谷歌搜索并查看了类似的问题,但没有找到答案:(
我还没有尝试过 PHP function mysql_insert_id() ,因为我真的很想用 SQL 来做到这一点。
最佳答案
关于php - MySQL- 为什么 LAST_INSERT_ID() 对我不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2033366/