Database is there but Wordpress cannot establishing a Database Connection - php

I am having a server running on my machine and I am calling it over the network. The Server is running fine and there have not been any problems with apache or php yet.
My database is not running on the same machine as apache but in the same local network on a server with the domain "sql.local.network.com".
Now i copied a Wordpress site onto my webserver which has been on another server in the same network, so it should work fine, since the database server is still accessable by both these webservers.
The problem now is, that Wordpress just shows the message Error establishing a database connection.
What I did was to access the database with phpmyadmin which I quickly set up on the server. This worked fine, and I was able to access the database.
Also I found a short skript:
<?php
$link = mysql_connect('sql.local.network.com', 'user', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
This echoed Connected successfully, which means a simple mysql_connect works fine as well.
Also I am able to ping sql.local.network.com over my console and get the response 192.168.0.101.
Everything works, but the Wordpress-page.
Is there a simple solution to fix the Wordpress connection problem I am missing?

Check the Privileges tab in phpmyadmin and look at the host column. If it's set to "localhost", then that dataabase user can only access the database from the same server as the database. To access remotely, change it to either "%" for any server or to the IP of the server you're trying to connect from.

Related

Connecting php and mysql database post production in web development

I wrote a simple user registration system that runs on my local machine using apache. (Localhost at port 8080).
My php file that tries to connect to mysql database looks like :
<?php
$con = mysqli_connect("localhost","root","","register");
//localhost will have to change to host name if hosted on different server... I think.
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
Everything works and I can register/sign in a user on my local machine.
I know that I have to change $con = mysqli_connect("localhost","root","","register"); once I am ready to upload my site to host it in a free server like surge.sh or github pages.
I pushed my site to github pages from my repository and when I click "Register" / "Sign in" it doesn't load the page instead it acts as if I want to download the .php file. How should I make the changes? I need some help and suggestions.

Error 500 ( Fatal Error ) using pg_connect() in php

im trying to use pg_connect to access postgres on another server,,
i did opened the remote access and i can use bash to connect to my postgres server ! and i did host all all client_ip/32 trust in config but when im trying to use pg_connect i get error 500 !
pgsql is also installed and i've checked it with function_exists('pg_connect') and i returns true !
my code is :
$dbconn = pg_connect("host=remote_IP port=5432 dbname=myDB user=postgres") or die("Could not connect");
i've also tried this and get fatal error 500 again
$dbconn = pg_connect("host=remote_IP port=5432 dbname=myDB
user=another_super_user_i_made password=user_password") or die("Could not connect");
what is the problem ?
when you are able to connect to a server from one machine on your network, but get a connection timed out issue from another machine, it usually is due to one of a few things.
1) DNS. The machine you are testing from (the "remote access" as you call it) is able to resolve the DNS name and the webserver running your PHP code is not. You can use actual IP address instead of DNS names to test this.
2) Connectivity. Different machines are connected in different ways in a network. If you are able to get to an IP from the "remote access" machine but the web server is having trouble connecting to it (with "connection timed out"), try connecting directly to that web server (using "remote access" like SSH) and see if you can connect manually from there.
If it's not a network related issue it could be an issue with your default PG timeouts. Try setting them manually with the connect string. Specifically, the "connect_timeout" option, like this:
$d=pg_connect('host=example.com user=pgsql dbname=postgres connect_timeout=5');
There was host blocking issue !
my client hosting was not enabling remote access to DB !
you should check with your hosting that they can trace your problem

Failing to connect remotely to MySQL after setting everything up correctly

I have an issue getting to connect remotely to a MySQL database.
My current set-up is as follows: I have a windows 2008 Server at work, placed behind a router (fixed IP). The router has DMZ configured to the server, which works perfectly fine for everything else I have tested including web server, VPN, FTP, etc... The firewall of the Server is opened to the necessary services on the corresponding ports. I can telnet to all these ports decently.
The only thing that I cannot get to work is remotely connecting to a MySQL database. I have done all of the following:
Forward port 3306 to the Server (through DMZ);
Configure MySQL to bind to 0.0.0.0:3306 (it automatically does that when not supplying a bind-address);
Configure a user account in MySQL with access from localhost;
Configure the very same user account (same name, password, rights) with access from '%';
Open port 3306 in the Windows Server's firewall.
I am subsequently trying to execute a PHP script from a hosted web server (elsewhere on the internet):
<?php
// Create connection
$conn = new mysqli(<host>, <username>, <password>);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
with <host>, <username> and <password> being the corresponding and correct credentials.
This script simply times out without reply and gives the expected error Connection failed: Can't connect to MySQL server on '<host>' (110). I can also not telnet on port 3306. Connecting from localhost works fine.
I don't know what else I have forgotten or done wrong. What am I missing?
I need this connection in order to keep my 'backup system' centralized on the hosted web server. I could run my 'backup system' locally on the mysql host, but that makes it harder to manage it from the central point. Beside that, I'd like to get it to work to actually know what's going on. I hate not getting this kind of thing to work.
Thanks for anyone who has ideas on what could be wrong.
Kenneth

MySQL remote access trouble?

I have a database set up on a godaddy server. It is configured to allow remote access, and there are a couple of websites I'm running which need to access this data. It works when accessed from another godaddy site, and I can connect from my development environment both at work and home. We recently set up hosting with mydomain.com.
Here is the code block that triggered it:
function connect(){
$servername = "XX.XX.XXX.XX";
$dbusername = "databaseusername";
$dbpassword = "mahpassword";
$dbname = "databasename";
try{
$newMysql = new PDO("mysql:host=".$servername.";dbname=".$dbname, $dbusername, $dbpassword);
}
catch(PDOException $e){
echo 'connection Failed: '. $e->getMessage();
die;
}
}
and now I'm getting this error message on the new site:
connection Failed: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'XX.XX.XXX.XX' (111)
The only problems I can think of is that either for some reason there are a limited number of IP addresses the MySQL database will connect to by default (which seems squirrely), I'm getting blocked by a firewall on the MySQL server (again.. doesn't make sense to me), or there is some setting on the mydomain hosting server disallowing remote requests (?)
I'm new to this kind of thing, so I'm open to any suggestions. I could probably just set up another database on the new site, but I don't want the hassle of keeping them synchronized if I don't need to. What might be wrong? Are there any workarounds?
[edit]
connected to remote database via console (mysql -h XX.XX.XXX.XX ...), the privileges were found under the information_schema database, a quick select * from SCHEMA_PRIVILEGES and select * from USER_PRIVILEGES shows that 'databaseusername'#'%' has sufficient privileges. Not that it helped me any, but maybe it'll help someone down the road.
[/edit]
As it has been more than a year since I asked this question, I suppose I need to answer it just to close it.
It turns out that godaddy had blocked mydomain.com servers via firewall ("Remote access" was limited). so in order to accomplish what I wanted to do, I had to copy and store the database on both sites.

PHP/MySQL simple connection won't work

I'm hosting a website on Zymic (free host) that utilizes MySQL. I opened an account, and wrote the SIMPLEST function to connect to the DB. It looks like this:
<?php
$conn = mysql_connect("uuuq.com","paulasplace_sudo","mypassword");
if(!$con)
{
die("Could not connect: " . mysql_error());
}
else
{
echo("mysql connected successfully!");
}
?>
but it throws this error:
Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in /www/uuuq.com/p/a/u/paulasplace/htdocs/index.php on line 9
Could not connect: Lost connection to MySQL server at 'reading initial communication packet', system error: 111
Any ideas what might be wrong?
This may be just from when you copied the code into your post, but you store the results of mysql_connect() into $conn, but the if statement checks a different variably $con...
For those like me that had this same problem with a virtual machine or where you have all the rights (priviliges as read in phpmyadmin) to make users, the problem for me was that my user for the database was created incorrectly . While creating my DB user i set incorrectly one the parametres right after the name there is an selector where you can choose the server: chosen as default was my error, that says "any server" and is set as % , i had to change it , infact , i had to create a new user with the same name and different server, there i set it to localhost. My problem got solved , i deleted my other user, restarted the server and it worked fine.
I suspect the hostname is "localhost" and not uuuq.com.
Often times these free hosts have their MySQL servers at different addresses altogether as opposed to simply localhost or the site address itself.
If the host provides access to phpMyAdmin, open that then look at the top of the page and you should see something along the lines of
Server: s1.mysqlserver.com
That is the address you want.

Categories