【发布时间】:2019-08-05 04:15:59
【问题描述】:
无法连接到 MySQL 数据库。第 8 行出错 - 变量 $conn 从未使用过。
希望有人可以帮助我。我是第一次编码,我的大部分教程都来自 YouTube。我使用 Eclipse 作为我的 IDE 和 XAMPP 作为我的本地服务器。
我正在尝试使用登录信息创建一个动态网站,因此我将其连接到 XAMPP 中的 MySQL,但我在第 8 行(黄色感叹号)中不断收到错误,其中显示变量 $conn 从未使用过。这些文件保存在 htdocs 中,所以我认为这不是问题。
当我尝试运行代码时,我收到一条错误消息:
Object not found!
The requested URL was not found on this server.If you entered the URL manually please check yourspelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.39 (Win64) OpenSSL/1.1.1c PHP/7.3.7
<?php
$dbServername = "localhost";
$dbUsername = 'root';
$dbpassword = "";
$dbName = "login_information";
$conn = mysqli_connect($dbServername, $dbUsername, $dbpassword, $dbName);
【问题讨论】:
-
variable $conn is never used是警告,而不是错误。编辑器说您创建了变量,但从未在任何地方使用它。 -
您将代码放在哪个文件中?你把代码放在哪里?你是如何运行它的?
-
我将代码放在 htdocs 文件夹中,然后创建了另一个文件夹,我将其命名为“includes”,所以基本上路径是 xampp\htdocs\PHPTest\includes。我使用 Eclipse 运行它。在浏览器中也试过了,得到了同样的错误信息。我还在我试图链接到登录页面的 htdocs 文件夹中创建了另一个名为 index 的代码。