누군가가 이것을보고 왜 작동하지 않는지 말해 줄 수 있습니까? 이것은 내가 작업하고있는 수업의 일부입니다. 삽입 쿼리는 잘 작동하고 $ char-> db-> insert_id를 호출하면; 클래스 밖에서도 작동합니다 ($ char가 클래스 임)mysqli insert_id가 작동하지 않습니다.
function createChar($charName, $charRace, $charClass) {
//put userId, charName and charRace into database
$sql="insert into characters (userID, name, race, class) values ('$this->userID', '$charName', '$charRace', '$charClass') ";
$result=$this->db->query($sql);
if($this->db->affected_rows == '1')
{
return '1';
}
else
{
return '0';
}
//get last insert id
$this->charID=$this->db->insert_id;
}
문제와 관련이 없지만 mysqli의 [real_escape_string] (http://php.net/manual/en/mysqli.real-escape-string.php)을 사용하여 모든 변수를 쿼리에 인용하는 것이 좋습니다. 현재 코드는 [SQL Injection] (http://en.wikipedia.org/wiki/SQL_injection)에 취약합니다. – lightster
이 단계는이 클래스 외부에서 수행됩니다. :) –