使用下面的代码,我自动递增一个 ID 值作为 constant_client 表中的主键,然后需要将其用作varying_client 表中的外键。第一个准备好的语句可以正常工作,并且设置为 $conn->insert_id 的 $id 变量似乎也可以工作,因为在回显该语句时,我从第一个表中获得了正确的增量值。但是,在尝试第二个查询时,我收到“调用 bool 上的成员函数 bind_param()”错误。
$stmt = $conn->prepare("INSERT INTO constant_client (on_programme, last_name, first_name, middle_name,
date_birth, gender, ohs, maiden_name, marital_status, ethnicity, height, weight, hair_colour,
eye_colour, tattoos, features, chronic, disabilities)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("isssssisssssssssss", $on_programme, $last_name, $first_name, $middle_name, $date_birth,
$gender, $ohs, $maiden_name, $marital_status, $ethnicity, $height, $weight, $hair_colour,
$eye_colour, $tattoos, $features, $chronic, $disabilities);
$stmt->execute();
$id = $conn->insert_id;
echo $id;
$stmt = $conn->prepare("INSERT INTO varying_client (id, address, suburb, postcode, state, client_phone, client_mobile
emergency_contact, emergency_phone)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param('issisiisi', $id, $address, $suburb, $postcode, $state, $client_phone, $client_mobile,
$emergency_contact, $emergency_phone);
$stmt->execute();
$conn->close();
我对准备好的语句很陌生,所以我完全有可能在某处弄乱了语法,但如果有人能对此有所了解,将不胜感激。