But now, I'm getting an error: Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host '
I can get to the mysql database on the server and Godaddy ran scripts that work. They said my parameters were correct but they say it's on my end. I'm talking directly to their server not a localhost. I tried it on my smart phone with a different IP and got the same message. If it's not them and not my code, what can it be? The error is on the $conn = line.
$hostname = "AAAA.server.net";
$username = "BBBB";
$dbname = "CCCCC";
$password = "XXXXX";
$usertable = "tblOne";
//Connecting to database
$conn = mysqli_connect($hostname, $username, $password) OR DIE
("Unable to connect to database! Please try again later.");
mysqli_select_db($conn, $dbname);
Be sure and confirm your database host, because the error message is talking of host problem
Unknown MySQL server host
With GoDaddy, your domain name may not be where your MySQL server resides. It depends upon your server type and your hosting plan. GoDaddy has a help page that will point you in the right direction:
https://support.godaddy.com/help/article/39/viewing-your-database-details-with-shared-hosting-accounts
Related
I am trying to use mysqli_connect as such:
$host = "ftp.tatiana-renae.com";
$user = "tatiana";
$password = "********";
$dbname = "********";
$connection = mysqli_connect($host, $user, $password, $dbname);
but I get this error:
Database connection failed: Can't connect to MySQL server on 'ftp.tatiana-renae.com' (111) (2003)
I know mysqli_connect works differently than mysql_connect but I can't figure out what to do for mysqli_connect to make it happy. Any ideas?
Error 111 is "connection refused". One candidate explanation is that MySQL is not "listening" on the network, but only the TCP loopback address.
Check the my.cnf for the server, and check if it contains lines like this:
skip-networking
or
bind_address=127.0.0.1
If your PHP is running on the same server as MySQL, you can try using '127.0.0.1' for the host, in place of 'ftp.tatiana-renae.com'.
Is the MySQL server running? Can you connect to it using the mysql command line interface?
There's several other possibilities; but there's not enough information provided about you environment for us to accurately diagnose the problem. We're just guessing.
HI friends I wants to connect local server (linux) to a remote desktop's mssql database. I have reviewed the php document for assistance.
It defines the use of mysql_connect().
I used that and ends with some issues mainly do to the difference in domain.
Here is the datas I have.
$dbname = 'dbname';
$servername = 'servername.abc.cbd.net\instancename';
$username = 'domain\username';
$password = 'password';
$port = '1433';
Here is the connection code I have used.
$link= mssql_connect($servername, $username, $password);
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
Error am getting is
Warning: mssql_connect(): Unable to connect to server:servername.abc.cbd.net\instancename
Please help me to correct the code. Is there any other alternative for myssql_connect().
Thanks in advance.
Trying to connect to a database that is not on the same host as my site for the first time and not having much luck. The DB is on a godaddy host and I have configured it to allow remote access:
$dbc = mysqli_connect($db_host,$db_user,$db_pass,$db_name);
if (!$dbc) {
die('Connect Error: ' . mysqli_connect_error());
}
and I get the following on page:
Warning: mysqli_connect() [function.mysqli-connect]: [2002] Connection
timed out (trying to connect via ‘mydbhostname:3306) in ‘path’ on line
3
Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2002):
Connection timed out in ‘path’ on line 3
Connect Error: Connection timed out
Anything I need to look for on my end or something in the script that could be causing this?
EDIT: well it appears everything works when I use mysql, but not mysqli...and mysqli is enabled on the server.
I had the same problem on a Digitalocean Ubuntu 14.04 server, where the firewall configuration was the culprit. Mysql wasn't allowed on port 3306 by the ufw firewall rules.
Solution:
$ sudo ufw status
$ sudo ufw allow mysql
$ sudo ufw reload
Make sure that you have inserted correct hostname for your database, here you can see how to do it on godaddy hosting:
http://support.godaddy.com/help/article/4978/connecting-remotely-to-shared-hosting-databases
http://support.godaddy.com/help/article/39/locating-your-databases-host-name?locale=en
I don't understand the difference between mysqli and mysql, but I've found on GoDaddy that using:
mysqli_connect doesn't work.
mysql_connect does work.
Try using the following sample code to see if you can connect to your database which needs data in at least one table:
<?php
//Variables for connecting to your database.
//These variable values come from your hosting account.
$hostname = "XXXXXXX.db.XXXXXXXX.hostedresource.com";
$username = "XXXXXXX";
$dbname = "XXXXXXX";
//These variable values need to be changed by you before deploying
$password = "XXXXXXX";
$usertable = "XXXXXXX";
$yourfield = "XXXXXXX";
//Connecting to your database
mysql_connect($hostname, $username, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($dbname);
//Fetching from your database table.
$query = "SELECT * FROM $usertable";
$result = mysql_query($query);
if ($result) {
while($row = mysql_fetch_array($result)) {
$name = $row["$yourfield"];
echo "<h2>some data</h2>";
echo "$name<br>";
}
}
?>
I want to ask about how to connect my localhost application (C:xampp/htdocs/myproject) to database at my server host (www.someweb.somedomain)?
Am I possible to do that? If it is, how to connect it at my php config? Right now my config (server.php) is:
<?php
$host = "my web IP public:3306";
$user = "root";
$pass = "";
$db = "dispatcherDB";
$conn = mysql_connect($host, $user, $pass) or die ("Cant connect to mySQL");
mysql_select_db($db);
?>
what I got:
Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in C:\xampp\htdocs\XMS\server.php on line 7
So, what must I filled for $host? I'm trying using website IP, it still can't connect. Maybe there's someone here have experience at this problem?
Sorry for my bad English
If you have cPanel access to the remote server then you need to mention that from which ip addresses it should allow access to MySQL..
In cPanel you will get Remote MySQL under heading Databases:
Clicking Remote MySQL will give you the option to add hosts from where you want to allow connections to your MySQL server:
Also, you can check localhost without specifying port number as value of $host..
Probably Mysql server is not allowed root access from remote servers.
you could check this post
I've made mysql.php file which contain codes to connect to my database.
However, i'm getting this error message over and over again.
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061) in C:\CustomerData\webspaces\webspace_00290195\wwwroot\mysql.php on line 7
Warning: mysql_select_db() [function.mysql-select-db]: Can't connect to MySQL server on 'localhost' (10061) in C:\CustomerData\webspaces\webspace_00290195\wwwroot\mysql.php on line 8
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\CustomerData\webspaces\webspace_00290195\wwwroot\mysql.php on line 8
Unable to select database
I've checked if my username, host, database, and password were misspelled, but they were all correct.
I've looked around the internet, but couldn't seem to find the right one for my problem.
My mysql.php file contains:
<?php
// Mysql settings
$user = "example_example";
$password = "example";
$database = "example_example";
$host = "localhost";
mysql_connect($host,$user,$password);
mysql_select_db($database) or die( "Unable to select database");
?>
I've changed my user, password and host name to "example".
I just couldn't find the solution for myself, and I need your kind help.
Thank you in advance.
Please try to find out the error by using mysql_error() function as follows :
mysql_connect($host,$user,$password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
and then try to find the exact reason for the failure.
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061)
here a list of questions you have to do when this error appears:
1.- is mysql running on the server?
1.1.- is mysql running on default port or in a custom port?
1.2 - is mysql accepting connexions (from localhost, from an ip...?
1.3 - your firewall is blocking mysql?
2.- the database exists on the server?
3.- the user:password have access to that database?
3.1- the user:password can log in from localhost, from an ip... from any place that mysql
is accepting?
I think I don't forget anything
Please check first that your mysql server is running properly.
Mysql settings
$user = "example_example";
$password = "example";
$database = "example_example";
$host = "localhost";
$cn=mysql_connect($host,$user,$password);
mysql_select_db($database,$cn);
Please try this it may work
I am not expert of php but this code is working perfectly in my website
if you are getting any error after applying this code then please inform me i will rty to solve the problem.
Thanks
You should provide the connection that need to use from database whle selecting database. Also use single quote instead of double quotes.
<?php
// Mysql settings
$user = 'example_example';
$password = 'example';
$database = 'example_example';
$host = 'localhost';
$link = mysql_connect($host,$user,$password);
mysql_select_db($database,$link) or die( "Unable to select database");
?>
Reference
You have to get the database information first. You posted this problem when you try to connect to your database in your website hosting, right?
So, go to your hosting control panel to get the MySQL database (and take note of where the database is stored on! Sometimes some hosting providers don't use "localhost". Instead, some of them may use 'serverXX.yourhostingprovider.tld' where XX means the server ID), and then change the corresponding variables with the value you've obtained from the hosting control panel.