php - 解析错误:语法错误,第 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。
解决方案
;
在行尾使用
require "config.php";
推荐阅读
- python - sorted() 仅在第一次调用时失败
- python - 根据 URL 包含的最高参数过滤 URL 的 Python 列表
- python - 将 django 应用程序从 localhost 应用程序部署到 Web 应用程序
- laravel-5 - 为什么 DB::select 工作但 DB::table 不起作用?
- java - 为 servlet [dispatcherServlet] 提供错误 Servlet.service() 的自定义异常处理
- node.js - AWS Lambda 函数不会插入 Dynamo DB
- c - 为什么这个while条件没有捕捉到EOF?我得到分段错误
- php - 如何使用输入表单组合数组
- c++ - 如何将浮点算法转换为定点?
- php - 如何在 Yii2 项目中使用rectorphp/rector?