我正在尝试推出一个 CMS 网站,并且我在 1and1 Internet 的托管上。我正在尝试连接到我的 MySQL 数据库,但出现以下错误:



经过一番沮丧之后,我决定检查我的包含,结果发现以下代码不包含我的连接变量文件。

admin.php

<?php

include("connection.php");

$link = mysql_connect($connection_server, $connection_user, $connection_password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);

?>

connection.php
<?php

/* --------------------------------------
/
/   Bitachon.org Connection Variables
/
/   Created by: Moshe [Last Name]
/
/
/   Date: October 12, 2010
/
/
/   This file contains the connection
/   variable to connect to the MySQL
/   database that powers [site]
/
/  --------------------------------------*/

//Variable to confirm that the file has been included
$connnections_included = true;


/* --- Connection Variables ---*/

$connnection_server = "[server]";

$connection_database = "[db]";

$connection_user =  "[username]";

$connection_password = "[password]";

?>

怎么了?

最佳答案

问题出在你的 connection.php 文件中,其中有一个错字:

$connnection_server = "[server]";
  // ^-- third n

解决这个问题(以及 Josh's answer 中提到的 include() 问题)应该可以解决您的问题。

关于PHP 不包括连接信息,怎么了?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3927051/

10-16 16:32
查看更多