PHP mysql_real_escape_string():拒绝访问用户WWW的数据'@'localhost'的 [英] PHP mysql_real_escape_string(): Access denied for user 'www-data'@'localhost'

查看:486
本文介绍了PHP mysql_real_escape_string():拒绝访问用户WWW的数据'@'localhost'的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚上传我在生产服务器上的网站,我得到的错误:

 警告:mysql_real_escape_string():拒绝访问用户WWW的数据'@'localhost'的(使用密码:NO)在file.php上线106警告:mysql_real_escape_string():一个连接到服务器无法在file.php上线106建立

函数的code是

 包括('./../ INC / conn.php');
如果(使用isset($ _ GET ['查询']))$ Q =干净($ _ GET ['查询']);
清洁功能($ VAR){
    回报(mysql_real_escape_string($ VAR));
}

的code INC / conn.php:

  {尝试
  $ DNS ='MySQL的:主机=本地主机,数据库名= MyDatabase的';
  $ USER ='根';
  $ PW ='的rootpw';  $选项=数组(
    PDO :: MYSQL_ATTR_INIT_COMMAND => 集名称UTF8
    PDO :: ATTR_ERRMODE => PDO :: ERRMODE_EXCEPTION
  );  $ DB =新PDO($ DNS,$用户,$私服,$选项);
}赶上(例外$ E){
    回声连接错误,$ E-GT&;的getMessage();
    死();
}

我真的不知道是怎么回事,因为对我有我的本地开发Ubuntu的服务器上没有问题。 MySQL和Apache和PHP的版本是一样的。唯一的一点是我使用虚拟主机在Apache督促服务器上。不知道是怎么回事?是不是我错过了在Apache或者PHP配置?

之一

修改
这里是我的文件夹的权限:

 须藤的ls -l /home/user/public/domain.com/www/
共有28
drwxrwxr-X 13用户WWW的数据4096年08月22 12:30 adodb5
drwxrwxr-X 2的用户WWW的数据4096年08月22阿贾克斯12:30
drwxrwxr-X 2的用户WWW的数据4096年08月22 CSS 12:31
drwxrwxr-X 9的用户WWW的数据4096年08月22 GFX 12:33
drwxrwxr-X 2的用户WWW的数据4096年08月22 INC 12:33
drwxrwxr-X 2的用户WWW的数据4096年08月22 JS 12:34

我的Apache虚拟主机配置

 <虚拟主机*:80>
  #管理员电子邮件,服务器名称(域名),以及任何别名
  的ServerAdmin contact@domain.com
  服务器名www.domain.com
  ServerAlias​​ domain.com  #索引文件和文档根目录(其中公共文件的位置)
  的DirectoryIndex index.html的index.php文件
  DocumentRoot的/home/user/public/domain.com/www
        <目录/>
                有FollowSymLinks
                设置AllowOverride无
        < /目录>
        <目录/home/user/public/domain.com/www>
                有FollowSymLinks
                所有的AllowOverride
                为了允许,拒绝
                所有允许
        < /目录>
    ScriptAlias​​指令/的cgi-bin / / usr / lib目录/ cgi-bin目录/
    <目录/ usr / lib目录/ cgi-bin目录>
            设置AllowOverride无
            选项​​+ ExecCGI -MultiViews + SymLinksIfOwnerMatch
            为了允许,拒绝
            所有允许
    < /目录>  #日志文件位置
  LOGLEVEL警告
  错误日志/home/user/public/domain.com/log/error.log
  的CustomLog /home/user/public/domain.com/log/access.log结合
< /虚拟主机>

编辑2

确定这样的问题是我没有足够的MySQL服务器上的任何www数据的用户。所以我刚才添加的用户WWW的数据,没有密码,并在mysql中没有特权,这是工作的罚款。我将在未来尝试使用PDO引述许多mentionned。
感谢大家想帮我。


解决方案

  

注意,这个答案是可怕的,可能让你暴露安全漏洞。这是错误的解决方案。不要这样做。见进一步向下的实际问题的解决方案。这个答案得到了刚刚接受这一事实意味着的两个的人们不知道他们在做什么。


这是因为你在你的mysql数据库没有一个WWW的数据!

您可以通过phpmyadmin添加www数据的用户,并赋予该用户没有特权,它应该工作

I just uploaded my website on the production server and i get the error :

Warning: mysql_real_escape_string(): Access denied for user 'www-data'@'localhost' (using password: NO) in file.php on line 106

Warning: mysql_real_escape_string(): A link to the server could not be established in file.php on line 106

the code of the function is

include('./../inc/conn.php');
if(isset($_GET['query']))$q = clean($_GET['query']);
function clean($var){
    return(mysql_real_escape_string($var));
}   

the code of inc/conn.php :

try {
  $dns = 'mysql:host=localhost;dbname=mydatabase';
  $user = 'root';
  $pw = 'rootpw';

  $options = array(
    PDO::MYSQL_ATTR_INIT_COMMAND    => "SET NAMES utf8",
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  );

  $db = new PDO( $dns, $user, $pw, $options );
} catch ( Exception $e ) {
    echo "Connection error : ", $e->getMessage();
    die();
}

I really don't know what is going on since i have no problem on my local dev ubuntu server. Mysql, apache and php version are the same. The only thing is i use virtual host on the apache prod server. Don't know what is going on... Is there something i missed in one of the apache or php config ?

Edit Here are my folder's rights:

sudo ls -l /home/user/public/domain.com/www/
total 28
drwxrwxr-x 13 user www-data 4096 Aug 22 12:30 adodb5
drwxrwxr-x  2 user www-data 4096 Aug 22 12:30 ajax
drwxrwxr-x  2 user www-data 4096 Aug 22 12:31 css
drwxrwxr-x  9 user www-data 4096 Aug 22 12:33 gfx
drwxrwxr-x  2 user www-data 4096 Aug 22 12:33 inc
drwxrwxr-x  2 user www-data 4096 Aug 22 12:34 js

my apache virtual host config

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin contact@domain.com
  ServerName  www.domain.com
  ServerAlias domain.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /home/user/public/domain.com/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /home/user/public/domain.com/www>
                Options FollowSymLinks
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

  # Log file locations
  LogLevel warn
  ErrorLog  /home/user/public/domain.com/log/error.log
  CustomLog /home/user/public/domain.com/log/access.log combined
</VirtualHost>

Edit 2

Ok so the problem was i didn't have any www-data user on the mysql server. So i just added user www-data with no password and no privilege in mysql and this is working fine. I will in the future trying to use PDO quote as many mentionned. Thanks for everyone trying to help me.

解决方案

Note that this answer is terrible and opens you up to security vulnerabilities. It is the wrong solution. Do not do this. See further down for the actual solution to the problem. The fact that this answer got accepted just means that two people didn't know what they were doing.

It's because you haven't a www-data in your mysql database!

You can add the www-data user through phpmyadmin and give that user no privilege and it should work

这篇关于PHP mysql_real_escape_string():拒绝访问用户WWW的数据'@'localhost'的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆