我試圖從以前的查詢中拉出一個自動遞增的ID。我收到異常:1305功能THE_NAME_OF_MY_DATABASE.mysqli_insert_id不存在。哪裏可以找到函數是否存在?
- 這不能是一個語法錯誤是否正確?
我可以在哪裏修改mysql以具備此功能或需要重新設置的內容?我搜索了這個,發現混合的迴應。
$action = isset($_POST['action']) ? $_POST['action'] : ""; if($action == "create"){ //write the query for character creation $query = "(all of my stuff that I'm putting into another database that works)"; $query1 = "INSERT INTO playerskill (skillid, charid) VALUES ('".$_POST['skills']."',mysqli_insert_id()); "; //what happens when successful or not if($mysqli->query($query)) { echo $query ; echo "Character was approved."; }else{ echo "Database Error: Unable to update record."; echo $mysqli->errno; echo mysqli_error($mysqli); } } //what happens when successful or not if($mysqli->query($query1)) { echo $query1 ; echo "Character was approved."; }else{ echo "Database Error: Unable to update record."; echo $mysqli->errno; echo mysqli_error($mysqli); }
MySQL本地函數被稱爲'LAST_INSERT_ID()'。 MySQLi對它的包裝是mysqli_last_insert_id()。 PDO版本是'$ pdo-> lastInsertId()'。你正在做的是調用PHP的包裝函數。只需調用MySQL一個(LAST_INSERT_ID())。 –
當心!您的代碼看起來可能容易受到SQL注入攻擊。它看起來不像是正確地轉義'$ _POST ['skills']'。 – Spudley
你很容易受到[SQL注入攻擊](http://bobby-tables.com/)**,你應該[防衛](http://stackoverflow.com/questions/60174/best-way-to -prevent-sql -injection-in-php)你自己。 – Quentin