我刚刚安装了MAMP 4.1.1,我想我已经按照我想要的方式配置了所有内容。我切换到PFP 7.0.15,所以我可以使用phpMyAdmin,我可以用这段代码连接到mySQL:
<?php
// Read in db connection details
$config_ini = parse_ini_file("../include/config.ini",true);
// mySQL server connection info
$servername = $config_ini['mySQL_db']['servername'];
$dbname = $config_ini['mySQL_db']['dbname'];
$port = $config_ini['mySQL_db']['port'];
$username = $config_ini['Online_User']['username'];
$password = $config_ini['Online_User']['password'];
$dsn = "mysql:host=$servername;dbname=$dbname;port=$port;charset=utf8mb4";
// set the PDO error mode to exception
$opt = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
);
try {
$conn = new PDO($dsn, $username, $password, $opt);
echo "Connection successful!";
} catch(PDOException $e) {
//echo "Error: " . $e->getMessage();
die("Error: " . $e->getMessage());
}
我看到'连接成功!'在我的浏览器中。
但是当我打开一个与我的Mac Apache服务器和早期版本的PHP一起运行良好的页面时,我得到的代码没有查询结果:
<select class="form-control" id="contest-year" name="year" size="1" required>
<option value="<?php echo date("Y");?>"><?php echo date("Y");?></option>
<?php
include_once("../../include/connect_pdo.php");
$sql = "SELECT DISTINCT Year from tblmodelentry_online WHERE Year <> YEAR(CURDATE()) ORDER BY Year DESC";
$stmt = $conn->query($sql);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
if ($stmt->rowCount() > 0) {
// output data of each row
while($row = $stmt->fetch()) { ?>
<option value="<?php echo $row['Year']; ?>"><?php echo $row['Year']; ?></option>
<?php
}
}
$conn=null;
?>
</select>
我在下拉列表中看到的只是
“&GT;
我做错了什么?我的/ Applications / MAMP /日志文件中没有任何内容。