0
我有一個相當複雜的mysqli插入語句來做,因爲我需要從另外兩個表中收集數據,並且還可以在一個語句中使用一些可用於php的變量。高級MySQLi查詢語法
由於準備好的語句的變量順序,我感到困惑。 - 我只插入四個值,但爲了獲得t1和t2的值,我還在bind_param語句中引用了這三個附加變量。
我應該填充jobRoleID,companyID,DepartmentID的,competenceID與$ newJobRoleID,$ newCompanyID,t1.id,t2.id
$addJobCompetencies = $con->prepare("
INSERT INTO jobRoleCompetencies (jobRoleID,companyID,departmentID,competenceID)
WITH t1 AS (SELECT id FROM departments WHERE companyID = ? AND department = ?),
t2 AS (SELECT id FROM competencies WHERE companyID = ?)
SELECT ?,?,t1.id,t2.id FROM t1,t2");
if($addJobCompetencies) {
$addJobCompetencies->bind_param('isiii', $newCompanyID,$row['department'],$newCompanyID,$newJobRoleID,$newCompanyID);
$addJobCompetencies->execute();
} else {
echo $con->error;
}
$addJobCompetencies->free_result();
我得到一個語法錯誤,但我不是100%確定爲什麼。誰能幫忙?
感謝 丹