我正在制作简单的php网页,使用php5,mysql,Nginx。
连接到数据库时,它突然冻结,并且不向浏览器呈现任何内容 我的PHP代码就是这个。
<?php
$host = 'localhost';
$user = 'root';
$password = '123456';
$db_name = 'test';
$link = new mysqli($host, $user, $password, $db_name);
if($link->connect_errno) {
echo "<script>alert('Connection Error....')</script>";
}
if($link) {
echo "<script>alert('Successfully connected!');</script>";
}
?>
(LIB / connect_db.php)
<?php
include './lib/connect_db.php';
$create_user_query = 'CREATE TABLE ...';
$admin_user_query = 'INSERT INTO ....';
$create_widget_query = 'CREATE TABLE ...';
if($link->query($create_user_query) === TRUE) {
echo "<script>alert('Success!')</script>";
}
$link->close();
?>
(的init.php)
index.php还包含'./lib/connect_db.php',没关系。但是init.php总是会引起问题。
P.S。当我将init.php编辑为
时<script>alert('...');</script>
<?php
...
?>
它不会调用alert();
答案 0 :(得分:0)
您在(lib / connect_db.php)中的变量之前缺少 $ 语法错误
include '.lib/connect_db.php';
$create_user_query = 'CREATE TABLE ...';
$admin_user_query = 'INSERT INTO ....';
$create_widget_query = 'CREATE TABLE ...';
if($link->query($create_user_query) === TRUE) {
echo "<script>alert('Success!')</script>";
}
$link->close();