PHP mysql_real_escape_string():拒绝访问用户’www-data’@’localhost’
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP mysql_real_escape_string():拒绝访问用户’www-data’@’localhost’,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2804字,纯文字阅读大概需要5分钟。
内容图文
![PHP mysql_real_escape_string():拒绝访问用户’www-data’@’localhost’](/upload/InfoBanner/zyjiaocheng/904/9a73417adadf4730b3d649797be08cfb.jpg)
我刚刚在生产服务器上上传了我的网站,我收到错误:
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
函数的代码是
include('./../inc/conn.php');
if(isset($_GET['query']))$q = clean($_GET['query']);
function clean($var){
return(mysql_real_escape_string($var));
}
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();
}
我真的不知道发生了什么,因为我在我的本地开发ubuntu服务器上没有问题. Mysql,apache和php版本是一样的.唯一的问题是我在apache prod服务器上使用虚拟主机.不知道发生了什么…有没有我错过的apache或php配置?
编辑
这是我的文件夹的权利:
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
我的apache虚拟主机配置
<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>
编辑2
好吧问题是我在mysql服务器上没有任何www-data用户.所以我刚刚添加了用户www-data,没有密码,也没有mysql的权限,这个工作正常.我将在未来尝试使用PDO引用,正如许多人提到的那样.
谢谢大家试图帮助我.
解决方法:
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.
这是因为你的mysql数据库中没有www数据!
您可以通过phpmyadmin添加www-data用户并为该用户提供无权限,它应该可以正常工作
内容总结
以上是互联网集市为您收集整理的PHP mysql_real_escape_string():拒绝访问用户’www-data’@’localhost’全部内容,希望文章能够帮你解决PHP mysql_real_escape_string():拒绝访问用户’www-data’@’localhost’所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。