我有一个脚本试图获取我刚刚插入的自动增量字段的 insert_id。
$db = new mysqli("localhost", "user", "pass", "db");
for($xx=0;$xx<$quantity;$xx++){
//quantity is the total number of tickets bought
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
//exit();
}
$payer_email = $db->real_escape_string($payer_email);
$name = $db->real_escape_string($name);
$query = "INSERT INTO `ticketsConference2013` VALUES (NULL, '".$payer_email."', '".$name."', null)";
$db->query($query);
$ticketIdIs="";
$ticketIdIs = $db->insert_id;
$html.='<p style="text-align:center;line-height:100%">Ticket number'.$ticketIdIs.'</p>';
$textIs = $name." ".($xx+1)." of ".$quantity;
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Cell(0, 0, 'CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9', 0, 1);
$pdf->write1DBarcode($textIs, 'C39', '', '', '', 18, 0.4, $style, 'N');
}
$db->close();
它可以很好地插入数据库,但每次运行时插入 id 只给出初始插入编号。它不反映数据库中的实际插入数。
我已经阅读了一些关于此的内容,但尽管摆弄我无法使其工作