大家好,我遇到了问题。我有2个php文件
核心php(发生错误的地方):
<?php
include('getSecondDropDown.php');
$arrayForSecondDropdown[] = functionName();
foreach($arrayForSecondDropdown as $v){
echo "<option value='" . $v['Country_ID'] ."'>" . $v['Country_Name'] ."</option>";
}
?>
getSecondDropDown.php:
<?php
include('config.php');
function functionName(){
$Region_ID =$_POST['Region_ID'];
$option="";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT Country_ID, Country_Name FROM Countries WHERE Region_ID ='".$Region_ID."'");
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach($stmt as $v) {
echo "<option value='" . $v['Country_ID'] ."'>" . $v['Country_Name'] ."</option>";
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
echo $option;
?>
完整错误代码(在Web控制台中显示 - 来源):
Country: <select name="Country_ID" id="Country_ID" form="ServiceForm">
Error: SQLSTATE[HY000] [2002] No such file or directory<option value=''></option></select></br>