简体   繁体   English

mysql_connect在通过VPN的服务器中不起作用

[英]mysql_connect not working in a server over a VPN

My "mysql_pconnect() / connect() "` function doesn't work on a server over a VPN. 我的"mysql_pconnect() / connect() ”`函数在VPN上的服务器上不起作用。 I used the VPN to access the server where in there I created a PHP website. 我使用VPN访问服务器,并在其中创建了一个PHP网站。 When I run my website it's a blank page. 当我运行我的网站时,它是空白页。 I was wondering why it is a blank page, so I find the error, now the error is the database connection. 我想知道为什么它是空白页,所以我找到了错误,现在错误是数据库连接。 but it's just the same with my localhost, and the website on my localhost is working. 但与本地主机相同,本地主机上的网站正在运行。 but when I transfer my website to the server it's not working. 但是当我将网站传输到服务器时,它无法正常工作。 is there something to do with the VPN? 与VPN有关系吗? My user and pass to connect to the mysql is correct. 我的用户并通过以连接到mysql是正确的。

main.php main.php

error_reporting(E_ALL); 
$settings_dir = "./settings";
require_once("$settings_dir/database2.php");
//etc etc codes..

database2.php database2.php

$conn=mysql_connect("localhost","root","passw0rd");

thats because you cant give the same arguments to mysql_pconnect() which you gave in case of your localhost.because where you hosted your website,there u will have diffrent server name ,DBname and DB password. 那是因为您不能给mysql_pconnect()提供与在本地主机时提供的相同的参数。因为您托管网站的位置不同,所以您将拥有不同的服务器名称,DBname和DB密码。

mysqli_connect(server,user,pwd,newlink,clientflag)

here the first argument is server which is the hostname,in case of local server its localhost but when you are using any remote server than u need to specify that server name.similarly username and password will be different for that server. 这里的第一个参数是server,它是主机名,如果是本地服务器,则为localhost,但是当您使用任何远程服务器时,您都需要指定该服务器username ,该服务器的usernamepassword也不同。

read here 在这里阅读

http://www.w3schools.com/php/func_mysql_connect.asp http://www.w3schools.com/php/func_mysql_connect.asp

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

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