将数据库中输入的最后一个主键id作为变量


Take the last primary key id enter in the database to var

我需要选择我在数据库中输入的最后一个id,并将其放入一个变量中

$timId = "" ;

但我试过这样的东西:

$requete = $bdd->prepare('SELECT LAST(`timId`)  FROM `timesheets`   ');
$requete->execute(array('timId'=> $_POST['timId'])) or die(print_r($requete->errorInfo()));
$resultat = $requete->fetch();
$timId = $resultat['timId'];
echo($timId);   

我知道我的SQL语法是错误的,但我该怎么做呢?

Use Order BY id Desc , Using limit clause you can achieve this 

如果使用mysql,通常应该使用"select last_insert_id()"

当然,这是假设您使用的是auto_increment列。

此外,根据$bdd的类,它可能有一个方法来获取最后插入的id。