UNION
ステートメントを使用してそれを実現できます。これを試して:
$dbh = new PDO('...');
$where = 'WHERE LoginEmail = :email AND LoginPass = :pass';
$query = [];
foreach (['safe_workers', 'safe_companies', 'safe_customers'] as $table) {
$query[] = "(SELECT LoginEmail, ID FROM {$table} {$where})";
}
/*
* This will become something like this:
* (SELECT LoginEmail, ID FROM safe_workers WHERE LoginEmail = :email AND LoginPass = :pass)
* UNION
* (SELECT LoginEmail, ID FROM safe_companies WHERE LoginEmail = :email AND LoginPass = :pass)
* UNION
* (SELECT LoginEmail, ID FROM safe_customers WHERE LoginEmail = :email AND LoginPass = :pass)
*/
$stmt = $dbh->prepare(implode(' UNION ', $query));
$stmt->bindParam(':email', $_POST['inEmail']);
$stmt->bindParam(':pass', $_POST['inPass']);
if ($stmt->execute()) {
var_dump($stmt->fetch(PDO::FETCH_ASSOC));
}
注: PDO を使用してステートメントを準備し、POST データをエスケープしています。そのマニュアルを見てください。