首页 > 解决方案 > 解析错误:语法错误,第 10 行 E:\wamp64\www\project-trial\install.php 中的意外 'try' (T_TRY)

问题描述

我正在尝试使用此文件为我的项目安装数据库 - install.php 代码如下:

<?php
/*
** Open a connection with the database via PDO to create a new database and 
tables with structure & insert initial values.
*/

require "config.php"
/*
** CREATING DATABASE CONNECTION**
*/
try{
   $conn = new PDO("mysql:host=$host", $username, $password, $options);
   $sql = file_get_contents("data/init.sql");
   $conn->exec($sql);
   echo "Databse and Tables created successfully. :)";
}catch(PDOException $error){
   echo $sql."<br>".$error->getMessage();
}
?>

如果我删除 try...catch 实现。然后它显示错误意外 $conn。这与 PDO 对象的创建有什么关系。PDO 不会与
PHP 5.6.35 一起运行。我正在使用 WAMP 3.0。

标签: phphtmlpdotry-catch

解决方案


;在行尾使用

require "config.php";

推荐阅读