我想从外部文件访问下面的方法(从公共类youth_teams)中的$ 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正确的路径?
他也应该指定这个函数的参数 –
有没有办法只取出$ new_id的值呢? – cpcdev
我更新了我的原始代码以显示流程。在运行addTeam()方法后,我希望能够获取$ new_id值,然后使用它来运行另一种方法 – cpcdev