简体   繁体   English

文件在虚拟服务器中不起作用

[英]File Doesn't Work in Virtual Server

I have a PHP file called footer10.php that worked just fine in shared hosting. 我有一个名为footer10.php的PHP文件,该文件在共享托管中工作得很好。 I moved it to a virtual server and it no longer works. 我将其移至虚拟服务器,并且不再起作用。

I get these errors when I pull the file up in a browser: 在浏览器中上载文件时出现以下错误:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'apache'@'localhost' (using password: NO) in /var/www/.../...com/httpdocs/.../footer10.php on line 23

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /var/www/.../...com/httpdocs/.../footer10.php on line 23
Access denied for user 'apache'@'localhost' (using password: NO)

This is on line 23 of the file: 这是在文件的第23行:

$presult = mysql_query("SELECT COUNT(*) FROM submission") or die(mysql_error());

Any idea what I need to do to make the file work on the virtual server? 知道我需要做些什么才能使文件在虚拟服务器上运行?

Thanks in advance, 提前致谢,

John 约翰

The error message means that PHP could not connect to the MySQL database. 错误消息表示PHP无法连接到MySQL数据库。

If you're establishing the connection on your own using mysql_connect you should make sure that host, user and password are correct (according to the error message no password was specified) 如果您使用mysql_connect建立连接,则应确保主机,用户和密码正确(根据错误消息未指定密码)

The user name and the empty password makes me think you've relied on the mysql.default_* settings on your old server. 用户名和空密码让我觉得你依赖旧服务器上的mysql.default_*设置。 You can specify a default server in your php.ini, refer to the manual for this. 您可以在php.ini中指定默认服务器,请参阅手册 The connection will then be opened automatically by php. 连接将由php自动打开。

So what you have to do is to find out correct credentials for your MySQL server. 因此,您要做的就是为MySQL服务器找出正确的凭据。 Then you either establish a connection using mysql_connect / mysql_pconnect or add it to the php.ini. 然后使用mysql_connect / mysql_pconnect建立连接或将其添加到php.ini。

Access denied for user 'apache'@'localhost' (using password: NO) , what does this line mean ? 用户'apache'@'localhost'的访问被拒绝(使用密码:NO),这行是什么意思? It means you need to update you're mysql connection settings with the correct ones ( username , password and host ) by this i mean you're mysql connection settings on the new server are different than the ones on the old server . 这意味着您需要使用正确的(用户名,密码和主机)更新您的mysql连接设置,我的意思是您在新服务器上的mysql连接设置与旧服务器上的不同。 Then make shure to move the database from one server to another . 然后使shure将数据库从一台服务器移动到另一台服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM