Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysql_real_escape_string():拒绝用户访问';根'@';本地主机';(使用密码:否)_Php_Mysql - Fatal编程技术网

Php mysql_real_escape_string():拒绝用户访问';根'@';本地主机';(使用密码:否)

Php mysql_real_escape_string():拒绝用户访问';根'@';本地主机';(使用密码:否),php,mysql,Php,Mysql,我发现这个错误在我的错误日志中重复出现,我相信它会导致内存泄漏,导致我的站点停机 PHP Warning: mysql_query(): Access denied for user 'root'@'localhost' (using password: NO) in /mysql.class.php on line 74 PHP Warning: mysql_query(): A link to the server could not be established in /mysql.

我发现这个错误在我的错误日志中重复出现,我相信它会导致内存泄漏,导致我的站点停机

PHP Warning:  mysql_query(): Access denied for user 'root'@'localhost' (using password: NO) in /mysql.class.php on line 74

PHP Warning:  mysql_query(): A link to the server could not be established in /mysql.class.php on line 74

PHP Warning:  mysql_real_escape_string(): Access denied for user 'root'@'localhost' (using password: NO) in /functions.php on line 380

PHP Warning:  mysql_real_escape_string(): A link to the server could not be established in /functions.php on line 380

PHP Warning:  mysql_query(): Access denied for user 'root'@'localhost' (using password: NO) in /mysql.class.php on line 100

PHP Warning:  mysql_query(): A link to the server could not be established in /home/glo/mysql.class.php on line 100
在mysql.class.php中,下面是从第72行到第104行的代码

function &execute () {
    $query = $this->read();
    **$res = mysql_query($query);** // line 74

    if ($res || mysql_errno() == 1062) {
        return $res;
    }
    $mysql_error = mysql_error();
    $mysql_errno = mysql_errno();

    // If debug_backtrace() is available, we can find exactly where the query was called from
    if (function_exists("debug_backtrace")) {
        $bt = debug_backtrace();

        $i = 1;

        if ($bt[$i]["function"] == "SQL_Query_exec_cached" || $bt[$i]["function"] == "get_row_count_cached" || $bt[$i]["function"] == "get_row_count")
            $i++;

        $line = $bt[$i]["line"];
        $file = str_replace(getcwd().DIRECTORY_SEPARATOR, "", $bt[$i]["file"]);
        $msg = "Database Error in $file on line $line: $mysql_error. Query was: $query.";
    } else {
        $file = str_replace(getcwd().DIRECTORY_SEPARATOR, "", $_SERVER["SCRIPT_FILENAME"]);
        $msg = "Database Error in $file: $mysql_error. Query was: $query";
    }

    mysql_query("INSERT INTO `sqlerr` (`txt`, `time`) 
                 **VALUES (".sqlesc($msg).", '".get_date_time()."')");** // line 100

    if ( function_exists('show_error_msg') )
         show_error_msg("Database Error", "Database Error. Please report this to an Admin.", 1);
}
在functions.php中,下面是代码

// MySQL escaping
function sqlesc($x) {
if (!is_numeric($x)) {
   $x = "'".mysql_real_escape_string($x)."'"; // Line 380
}
return $x;
}
我的连接代码是

function_exists("mysql_connect") or die("MySQL support not available.");

@mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die('DATABASE: mysql_connect: ' . mysql_error());
@mysql_select_db($mysql_db) or die('DATABASE: mysql_select_db: ' . mysql_error());

非常感谢您为调试这些错误提供的任何帮助….

可以在php.ini或apache配置文件中关闭显示错误

您可以在脚本中打开它:

   <?php 
          error_reporting(E_ALL);
          ini_set('display_errors', 1);
    ?>

把上面的脚本写在页面顶部,你们就会看到错误消息。
您应该在php错误日志中看到相同的消息。

这里的问题似乎是连接超出了函数的作用域,因此mysql函数正在尝试创建一个没有任何凭据的新连接

尝试将连接分配给变量,然后在函数中将其作为全局变量调用

$conn = @mysql_connect($mysql_host, $mysql_user, $mysql_pass);

function &execute () {
    global $conn;
    $query = $this->read();
    $res = mysql_query($query, $conn); 
    ....
您可以在这里的PHP手册中阅读有关作用域的更多信息

注意:不建议使用全局变量-最好使用更面向对象的方法并在MySQL类中创建连接,例如:

public function connect ($host, $user, $pass) {
    $this->connection = mysql_connect($host, $user, $pass);
}

function &execute () {
    $query = $this->read();
    $res = mysql_query($query, $this->connection); 
    ....
然后用这样的东西来连接

$db = new MysqlClassName();
$db->connect($mysql_host, $mysql_user, $mysql_pass);

检查
$mysql\u host
$mysql\u user
$mysql\u pass
的值是否正确…从听起来,您有连接问题。是否确实允许用户访问SQL Server和相应的表?而且用户确实没有密码?dbconnection的值都是正确的。。正如我们所说,站点正在运行,但这些错误不知何故发生了……您是否在连接之前调用了这些函数中的任何一个?还绝对确保不需要密码,并且用户不限于特定的ip?(即使这听起来是多余的,我在过去也遇到过类似的错误消息,当时我已经三次忽略了为用户设置特定IP的问题)因此我的代码没有问题,我认为有些函数已经弃用了…弃用不会立即引起问题(只是一些信息性消息).我刚打开它,我看到很多错误。。。注意:未定义变量:等待注意:在。。。一旦我设置为显示错误,这些错误就会显示。无论哪种错误都会发生。只是它们的重要性很低(尽管最好是修复它们),因此通常默认错误处理会忽略它们。