gpt4 book ai didi

mysql - 我想获得最后插入的 ID

转载 作者:行者123 更新时间:2023-11-30 22:16:26 26 4
gpt4 key购买 nike

有2个表quotedetails和quotationmaster以及一个公共(public)字段QuoteNo。 SNO是行情大师的主键。我想获得最大的 sno 并使用它我想将相同的 QuoteNo 插入到 2 个不同的表中。这是我的代码。

$response = '';
$customer=TableRegistry::get('quotationmaster');
$query=$customer->query();
$this->set(array('data'=>$query));
$response = $customer->find();
foreach($response as $row)
{
//echo $row['QuoteNo'];
$x++;
}
$qno = $x + 1;
$nqno = 'Q1-'.$qno;
$query->insert(['QuoteNo'])->
values(['QuoteNo'=>$nqno])->execute();
if($query)
{
$this->Flash->success('Saved');
$this->redirect(['controller'=>'Stockcheck','action'=>'index']);
}

$quotedetails=TableRegistry::get('quotationmaster');
$detquery=$quotedetails->query();
$options = $detquery->select(['QuoteNo'],['SerialNO' => $query->func()->MAX('SNO')]);
$qresponse = $quotedetails->find('all', $options);


Any helps are appreciable...

最佳答案

你可以尝试使用:

echo $this->SNO->getInsertID();
echo $this->SNO->getLastInsertID();

您可以使用上述任何一种方法来获取最后插入的 ID。

关于mysql - 我想获得最后插入的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38139388/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com