【问题标题】:In the book PHP and MySQL Missing Manuals 2nd Edition, I get error: Warning: mysql_connect() [function.mysql-connect]: Access denied for user在 PHP and MySQL Missing Manuals 2nd Edition 一书中,我收到错误:警告:mysql_connect() [function.mysql-connect]: Access denied for user
【发布时间】:2013-02-18 16:24:40
【问题描述】:

我正在使用 zymichost.com 试图按照标题中的书。

这是我得到的错误:

警告:mysql_connect() [function.mysql-connect]:访问被拒绝 用户'831445_juzer'@'192.168.1.1'(使用密码:YES) /www/zymichost.com/6/5/4/654456/htdocs/phpMM/connect.php 在第 5 行

警告:无法修改标头信息 - 标头已由 (输出开始于 /www/zymichost.com/6/5/4/654456/htdocs/phpMM/connect.php:5) 在 /www/zymichost.com/6/5/4/654456/htdocs/phpMM/scripts/app_config.php 上 第 25 行

这是 app_config.php 文件:

<?php

// Set up debug mode
define("DEBUG_MODE", true);

// Site root
define("SITE_ROOT", "/phpMM/");

// Database connection constants

define ("DATABASE_HOST", "xxxxx");
define ("DATABASE_USERNAME", "xxxxx");
define ("DATABASE_PASSWORD", "xxxxxx");
define ("DATABASE_NAME", "xxxxxx");

// function debug print

function debug_print($message) {
   if (DEBUG_MODE) {
      echo $message;
   }
}

function handle_error($user_error_message, $system_error_message) {
   header("Location: show_error.php?" . "error_message={$user_error_message}&" . "system_error_message={$system_error_message}");
   exit();
}

?>

这是connect.php代码:

<?php 

require_once 'scripts/app_config.php';

if (!mysql_connect(DATABASE_HOST, DATABASE_USERNAME, "foo")) { handle_error("There was a problem connecting to the database " . "that holds the information we need to get you connected.", mysql_error());
}

echo "<p>Connected to MySQL!</p>";

if (!mysql_select_db(DATABASE_NAME)) {
handle_error("There's a configuration problem with our database.", mysql_error());
}

echo "<p>Connected to MySQL, using database " . DATABASE_NAME . ".</p>";

$result = mysql_query("SHOW TABLES;");

if (!$result) {

handle_error("There's a problem looking up information in our database.", "Error in listing tables: " . mysql_error());

}

echo "<p>Tables in database:</p>";
echo "<ul>";
while ($row = mysql_fetch_row($result)) {
echo "<li>Table: {$row[0]}</li>";
}
echo "</ul>";

?>

一开始我以为是空格问题,但我猜不是这样的。

【问题讨论】:

  • 您的数据库用户名和/或密码错误。
  • 我已编辑您的问题以删除连接详细信息,它尚未获得批准,因此人们仍然可以看到它。请编辑您的问题并至少删除主机和密码。您遇到的问题是不正确的详细信息,这是一件好事!您意识到这是在互联网上,而您只是向人们提供了您的连接详细信息!
  • 如果那是书上的代码,那么你需要用你自己的替换作者的用户名/密码/主机。你可能应该扔掉这本书并获得一些更新的东西。 mysql 函数已弃用,不应再使用。
  • 警告:您所关注的图书已过时。不推荐使用mysql_xxx()函数;多年来一直没有被认为是好的做法,最近已被正式弃用。它们已被mysqliPDO 库所取代。
  • 您不能在任何输出后发送headers。在任何 echo 或 HTML 输出之后,您不能调用 header()

标签: php header warnings mysql-connect


【解决方案1】:

访问被拒绝意味着您的凭据错误。检查哪些凭据对您的数据库有效,并将它们输入到 app_config.php。

【讨论】:

    猜你喜欢
    • 2019-07-24
    • 2017-05-23
    • 2021-08-28
    • 1970-01-01
    • 2023-03-20
    • 2014-09-30
    • 2020-12-18
    相关资源
    最近更新 更多