解析错误:语法错误,第10行的E:\ wamp64 \ www \ project-trial \ install.php中出现意外的“尝试”(T_TRY)

时间:2018-06-30 13:02:06

标签: php html5 pdo try-catch

我正在尝试使用此文件为我的项目安装数据库-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。

2 个答案:

答案 0 :(得分:2)

在行尾使用;

require "config.php";

答案 1 :(得分:0)

您需要'config.php'后就忘记了分号