【发布时间】:2018-12-09 10:36:00
【问题描述】:
我正在尝试使用此文件为我的项目安装数据库 - 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。
【问题讨论】:
-
应该作为一个简单的错字关闭。