I have a system in Bluehost which I could connect easily to the database with
$con = new_mysqli("localhost", "username", "password", "database");
But I'm also trying to establish a second connection, but not in the Bluehost, but in a local server we have. So we created an outside IP for it so we can access the MySQL database that it has.
I try to connect it with this:
$con2 = new_mysqli("XXX.XX.XXX.XX", "root", "", "database");
But it only returns this error.
Connect failed: Can't connect to MySQL server on 'XXX.XX.XXX.XX' (110)
Why am I not connecting? Is there a configuration that I miss out?
You can comment for further details that I might have missed.
Related
I created a php website and host it online by using Heroku recently. However, I couldn't connect my database because I use localhost phpmyadmin database from my online site. How should I connect my localhost database from my online site? Or how to make my host my database online, and then make the connection? Here is my db.php file to make the connection with mysqli, in case if there's any need to tweak the db connection PHP codes.
//step 1: Establish database connection
DEFINE("DB_HOST", 'localhost');
DEFINE("DB_USER", 'root');
DEFINE("DB_PASS", '');
DEFINE("DB_NAME", 'my_db_name');
// Create connection
$con = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// Set charset to UFT8
mysqli_set_charset($con, "utf8");
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
If you are hosting your database on your local machine, whilst having a webserver that needs to connect to your database, you will have to make sure your database can be accessed by another machine. The host is only ‘localhost’ if the Local IP is identical for the machine and database. Your db.php is correct and will function properly, as long as you ensure that the connection details are correct, since localhost is not correct there will be errors.
You might want to look into how to portforward depending on what database software/installation you are using. Or look into whether your host offers database solutions sch as or similar to PhpMyAdmin (in case of most webhosts).
I have created two servers on Linux and installed LAMP on both, one I called web and the other is called app.
I would like to save a log from the web server on the app server - but when I try to connect to the app server, I get timeout.
My code is:
$mysqli = mysqli_connect("66:66:666:66", "username", "pass", "DB");
if (!$mysqli) {
die("Connection failed: " . mysqli_connect_error());
}
Where 66:66:666:66 is the ip to the app server.
I have in the app server under PhpMyAdmin added user privileges to a user with the name "username" and then the host is "%".
Have i forgotten something?
Edit: I have already tried to add port number 3306 to the connection.
I got following error:
Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server
on 'x.x.x.x' (111) in
/srv/disk1/2141710/www/vetalpallavi21.eu.pn/connection.php on line 7
Connection failed: Can't connect to MySQL server on '83.125.22.219'
(111)
I am hosting a site using free web hosting servers I don't know the IP address of that host server.So what should I give the first parameter in mysqli_connect() query and how can I get the IP address of that host.
If the server has mysql configured correctly you can use "localhost" instead of the IP address.
// use 172.0.0.1 OR "localhost"
$connection = mysqli_connect("127.0.0.1", "username", "password", "dbname");
// localhost:
$connection = mysqli_connect("localhost", "username", "password", "dbname");
the login details(username/password) are often emailed to you.
I am sure that information is included in the registration email. They send username and password along with php my admin login.
If that is the IP of the website you signed up at it's most likely not their SQL server(s).
PS: I am not sure if it's against stackoverflow TOS but it would be best if you don't show IPs for security and privacy :)
my connection string is:
$connection = mysql_connect("localhost", "root", "") or die("Could Not Connect to DB: ".mysql_error());
but on my computer i have installed IIS server first so localhost:80 is reserved by it so I changed my port to 8080 changing httpd.conf file in apache folder.
Now what should I change in connection string to connect to my database.
I am using XAMPP .
should I tried writing these:
1:
$connection = mysql_connect("localhost:8080", "root", "") or die("Could Not Connect to DB: ".mysql_error());
2:
$connection = mysql_connect("localhost,8080", "root", "") or die("Could Not Connect to DB: ".mysql_error());
But Not working Help please.
Thank You
Default port number which Mysql server uses is 3306
Web servers default port is 80
Web server and Mysql server are independent.
Do not change your api to connect to your mysql
I'm trying to connect to a mysql database from a different server to the one the database is hosted on but I'm getting an error.
I'm guessing it might be something to do with remote permissions. Is this something I can change or do I need to get my hosting company to do this?
<?php
$con = mysql_connect("mysql4-remote.hosting.net","myadmin","password123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>
Can't connect to MySQL server on 'mysql4-remote.hosting.net' (10060)PHP Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'mysql4-remote.hosting.net' (10060) in D:\websites\abc123\www\test.php on line 2
I would say, that your login credentials or Network settings are wrong:
See this post for further help:
http://wiki.answers.com/Q/What_does_MySQL_error_number_10060_mean
If you don't have access from outside use tunneling, here is an example:
$connection = ssh2_connect('SERVER IP', 22);
ssh2_auth_password($connection, 'username', 'password');
$tunnel = ssh2_tunnel($connection, 'DESTINATION IP', 3307);
$db = new mysqli_connect('127.0.0.1', 'DB_USERNAME', 'DB_PASSWORD',
'dbname', 3307, $tunnel)
or die ('Fail: '.mysql_error());
You have to give the permission to remote user by inserting the particular remote machine IP or wildcards in USER table in mysql.
This link will help you. Click Here