我想从外部文件访问下面方法中的 $new_id 变量(来自公共类青年队),但我不知道如何。我让它从包含该方法的文件中正确打印 lastInsertID,但也希望能够访问其他文件中的变量。
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;
}
这是我从其他文件中尝试过的代码:
sw::shared()->youth_teams->addTeam (
$team_name,
$error
);
$temp_two = sw::shared()->youth_teams->addTeam->pdo->lastInsertID();
echo "new id: " . $temp_two . "<br>";
当然这不起作用...访问 $new_id 的正确路径是什么?