외부 파일에서 아래 메소드 (public class youth_teams)에있는 $ new_id 변수에 액세스하고 싶습니다. 어떻게해야 할지를 알 수 없습니다. 메서드를 포함하는 파일 내부에서 lastInsertID를 올바르게 인쇄했지만 다른 파일의 변수에도 액세스 할 수 있기를 원합니다. $ NEW_ID에 액세스 할 수있는 올바른 경로는 무엇인가 ... 작동하지 않습니다 물론다른 파일에서 클래스에 저장된 변수에 액세스
sw::shared()->youth_teams->addTeam (
$team_name,
$error
);
$temp_two = sw::shared()->youth_teams->addTeam->pdo->lastInsertID();
echo "new id: " . $temp_two . "<br>";
: 여기
public function addTeam(
$team_name,
&$error
) {
$query = $this->pdo->prepare('INSERT INTO `' . $this->table . '` (
`team_name`
) VALUES (
:team_name
)');
$query->bindParam(':team_name', $team_name);
$query->execute();
print_r($query->errorInfo());
print $this->pdo->lastInsertID();
$new_id = $this->pdo->lastInsertID();
return $new_id;
}
내가 다른 파일에서 시도한 코드입니까?
그는이 함수의 매개 변수도 지정해야합니다. –
은 $ new_id 값을 꺼내는 방법이 있습니까? – cpcdev
흐름을 표시하기 위해 원래 코드를 업데이트했습니다. addTeam() 메서드가 실행 된 후 $ new_id 값을 가져 와서 다른 메서드를 실행하는 데 사용할 수 있기를 원합니다. – cpcdev