My "mysql_pconnect() / connect()"` function doesn't work on a server over a VPN.
I used the VPN to access the server where in there I created a PHP website. 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? My user and pass to connect to the mysql is correct.
main.php
error_reporting(E_ALL);
$settings_dir = "./settings";
require_once("$settings_dir/database2.php");
//etc etc codes..
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.
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.
read here
http://www.w3schools.com/php/func_mysql_connect.asp
Related
Error establishing a database connection
This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.
Are you sure you have the correct username and password?
Are you sure you have typed the correct hostname?
Are you sure the database server is running?
If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.
Try Again
.
How to resolve this Error.. ?
I've tried Wordpress installation on both Xampp and Wamp servers...
getting the same error every time..on both servers.
The error message says everything you have to know. Wordpress can not contact MySQL. Look in your wp-config.php if the MySQL-crendentials are correct. Find more information at https://wordpress.org/support/article/how-to-install-wordpress/.
I am trying to access to the database of my live website from localhost. My website is working on cpanel hosting.
I created database and added user to that database but can not connect to this database from my localhost .
this is the code of database information
<?php
$conf['dbuser']='admin_root';
$conf['dbpass']='rootroot!##$';
$conf['dbname']='bsaiiian_os';
$conf['dbhost']='example.com';
$conf["title"]='DEMO';
?>
I think the problem is from $conf['dbhost'] variable where I'm putting the url of my site and not sure if that is right.
When I'm uploading my script to the hosting and put
$conf['dbhost']='localhost';
the connection is established .
this is error message:
Connection failed: No connection could be made because the target machine actively refused it.
Due to security reasons cPanel's MySQL requires that you allow your IP in order to have access.
This is done through:
cPanel -> Remote MySQL Connection
You need to navigate there and allow your local computer's IP in order to make the connection.
Side Note: This stands true for all IPs, even the server's one that your account is hosted on. You will see your cPanel account's IP already present in there - this is to allow access to MySQL for any files from your cPanel account
i am trying to connect my site from others computers on local network. I can access the site from my system IP address but issue is this when i entered the username and password it will redirect the page from 192.168.0.2/ppp/login to localhost/ppp/auth/login and shows thee error localhost refused to connect.
localhost usually points to 127.0.0.1 . So, if you are getting redirected to localhost/login/ppp then the issue with your site's code. Don't redirect to http://localhost/login/ppp. Just do a redirect to /login/ppp instead.
The reason connection is refused is because the other PC doesn't have XAMPP (or any other web server) running on it.
your only need to change the config.php file in controllers. write your IP instead of localhost. Your code will run properly on network.
I'm trying to connect to a remote database on a server which is accessed through cPanel.
I created a user name and associated it with a database. I'm using:
I'm confused on the host name to use. I tried using the Main Domain name in the left menu panel in cPanel with the port number 3306 but it wouldn't work. I used the shared IP as well with the port number that that wouldn't work as well. I have added my local machine IP to the remote databases page in the cPanel as was told in a post but finally I'm not able to connect to the database.
On echoing the mysql_error(), I get:
Can't connect to MySQL server on 'host_name' (4)
Any help would be great!
your hosting site will specify which name should be used for the host
in hostinghood.com they says that to use localhost itself as host name
so check what your hosting site says about it
I have a user called 'test'#'111.11.11.111' (for example).
When i call
mysql_connect('localhost', //mysql is hosted locally (as far as php is concerned)
'test', //user is test
'password');//test's password
it automatically tries to login 'test'#'localhost'. Trying test#111.11.11.111 for username results in test#111.11.11.111#localhost to try logging in.
Can I tell php or mysql to log in 'test'#'111.11.11.111'?
EDIT: The mysql server is hosted on localhost (from php's perspective). The IP of server hosting the mysql database is something other than 111.11.11.111. The user is logging into the mysql server from IP address 111.11.11.111
Did you try using 111.11.11.111 in place of 'localhost'? that should generate test#111.11.11.111
maybe I am misunderstanding the question, but why can't you just change connect statement to
mysql_connect('111.11.11.111','test','password');
??
I don't think so, the point of setting where a user can connect from on the MySQL server (in this case '111.11.11.111') is for security. PHP can't override that security as far as I know.