I am trying to log-in remotely to MySQL server which is running on my Disk station, over the network. I confirm that MySQL is running on the disk station, I have php running on the disk station and I can check via remote connection to disk station phpMyAdmin and MySQL queries are answered.
On my laptop, I have created the following PHP script and when I try to run this script on my laptop, I get the following error message
<?php // login.php
$hn = 'bio12' ; //disk station name
$db = 'mysql' ; //database I want to connect to
$un = 'mysqluser' ; // user name
$pwd = 'abctest123' ; // password for the user
$conn = mysql_connect($hn, $un, $pwd);
if(! $conn){
die('Could not connect') ;
}
echo 'Successfully Connected';
?>
Error message: Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in C:\xampp\htdocs\login.php on line 15
Could not connect
I have tried using the IP address instead of 'bio12' but without success.
Interesting enough, when I use the same code and try to connect to local mysql (I am running XAMP on my laptop) and using the 'localhost' instead of 'bio12' it works just fine.
What am I doing wrong?
You need to allow remote connections. Find line in your mysql config (my.cnf file)
bind-address = 127.0.0.1
and comment it with "#" at the beginning, please also see this thread: How to allow remote connection to mysql
Related
I have been searching for an answer for last 3 days before posting.
I have installed SQL Server 2012 and, Apache24, PHP7.0
The Apache started fine, PHP7 Started fine
I can browse localhost/info.php and it shows perfect
Installed ODBC
Installed the SQL extensions drivers
Configured PHP.ini and apache conf file
SQL services started through SQL configuration manager
also allowed in the network configuration the TCP\IP and named pipes
I can't login to the SQL server using Microsoft SQL server manager
So all seems to be fine but every time I try to do a simple PHP code to connect my PHP to the SQL server I get the below error
Warning: mysqli_connect(): (HY000/2002): No connection could be made
because the target machine actively refused it. in
C:\Apache24\htdocs\index.php on line 13 Could not connect
Have disabled the firewall also and even added a rule with few ports
I am running on windows 10 Enterprise
Also when I change the server name to WALEED\SQLEXPRESS I get the below
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo
failed: No such host is known. in C:\Apache24\htdocs\index.php on line
13
Tried to search in the SQL server log but couldn't find any errors
All extensions for my PHP are working fine on info.php
Index file :
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$dbhost = 'localhost';
$dbuser = 'admin';
$dbpass = 'admin2017';
$db = 'sunto';
$conn = mysqli_connect($dbhost,$dbuser,$dbpass,$db);
if(! $conn){
die('Could not connect') ;
}
echo 'Successfully Connected';
$sql = 'Connected Successfully';
$retvalue = mysqli_query($sql);
if(! $retvalue){
die('Cannot connect to SQL: ');
}
echo 'DataBase test_db13 has successfully created';
mysqli_close($conn);
?>
In the comments you said:
what is strange when i Try to connect with sqlsrv_connect(
"localhost", $connectionInfo ); it is fine connected but when i try to
connect using mysqli. it shows error
There's nothing strange about that. The clue's right there in the name of the method you're using:
mysqli_connect()
That code library is for connecting to MySQL databases only.
You need to use the sqlsrv_ library instead if you want to connect to SQL Server. They're completely different database platforms, with completely different PHP libraries to use for working with them. As you saw yourself, it works when you use sqlsrv_connect.
I'm not really sure why you then tried to use mysqli after that, or why you expected that to be successful.
I try to connect my android application using JSON Parser to the web hosting. But whenever I try to connect (even just open using url in the browser) I will get the error message.
<?php
$dbHost = 'http://sql4.000webhost.com/localhost';
$dbUser = 'a6410240_cbetTD';
$dbPass = 'xxxxxx';
$dbName = 'a6410240_cbetTD';
$conn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($dbName,$conn);
?>
This is my database.php file. The full error message is
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'http' (4) in /home/a6410240/public_html/database.php on line 8.
I have tried change the $conn but still it didn't worked for me.
Thanks
If your database and application is on same server then use "locahost" in $dbhost.
And if your database and application is on different servers then you need to use IP address or hostname in $dbhost and the database user should be added on database server provided with required privileges.
The problem you are having was already mentioned in one of the comments, this one to be precise.
For your solution to work, all you need to do is omit the part http:// at the beginning and probably /localhost at the end.
The host is only the domain you are referring to. In this case sql4.000webhost.com. With /localhost you tried to already connect to a database, although your configured database is supposed to be a6410240_cbetTD.
MySQL use TCP port 3306 by default
($dbport) and hostname or IP address ($dbhost). For LAMP (Linux-Apache-MySQL-php) you can find a lot of tutorials.
Usually MySQL server listens internal port (which can't be reached via Internet) for security purposes.
If you familiar with docker, you can simply download examples of LAMP solutions from hub.docker.com.
As the title indicates I'm trying to link my MySQL database to my website using php.
I'm using GoDaddy hosting for the MySQL database and I got this code directly from them and it's still not working for some reason, giving the error below.
Here's my code :
<?php
$hostname = "trdlibrary.db.6253425.hostedresource.com";
$username = "*******";
$password = "*******";
$dbname = "trdlibrary";
$connect = mysqli_connect($hostname, $username, $password, $dbname, 3306) OR DIE ("Unable to connect to database! Please try again later or contact an administrator for help.");
?>
Here's the error :
Warning: mysqli_connect(): (HY000/2002): A connection attempt failed
because the connected party did not properly respond after a period of
time, or established connection failed because connected host has
failed to respond. in C:\xampp\htdocs\searchengine\dbconnect.php on
line 6 Unable to connect to database! Please try again later or
contact an administrator for help.
Can anyone see the issue?.. or is this something I need to contact GoDaddy's support line about.
-- EDIT --
I forgot to mention that I am running the web server off my local machine using XAMPP (so I can run the PHP scripts) but the MySQL server is off-site with GoDaddy, so 'localhost' won't work currently.
-- EDIT #2 --
So I learned that sadly, remote access of MySQL databases to GoDaddy requires a more expensive and 'higher tier' hosting package from them. So I just answered my own question, thanks to those who replied.
You have to setup remote access to databases on Godaddy. You can refer to this page to see how to enable it.
there's this server:
http://phpmyadmin.pvdata.fr/index.php ,
I can connect to it knowing the username and password and Server Choice.
Once I connect to it, it shows under MySql the following information: (I'm Translating from French)
Server: sql6 (sql6 via TCP/IP)
Server Version: 5.0.92-87
Protocol Version: 10
Username: pvdata#10.5.1.3
Character for MySql: UTF-8 Unicode (utf8)
So I tried using the following code in order to connect to the Database:
<?php
// Create connection
$username = "pvdata";
$password = "xxxxxxxx";
$hostname = "10.5.1.3";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
?>
But it didn't work, it's saying: "A connection attempt failed because the connected party did not properly respond after a period of time".
What am I doing wrong?
Go to your phpMyAdmin installation and look for the file config.inc.php. Open that file, and check which hostname / ip is being used for SQL6. That is the IP you should use for your mysql_connect()
This is most likely a firewall issue. Most 3rd party hosts don't allow you to access MySQL from 'the outside'.
You can do this if you manage the MySQL server yourself or if you have a host that doesn't deny you to access the database from another machine, but in regular web hosting, this is not common.
You need to search, google helps a lot, also you need to connect to an ip/domain and port of your MySQL server.
For this, you need to know what is the port of your mysql server.
Look this answer from link
<?php
mysql_connect("mysite.com:3306", "admin", "1admin") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
to check if you have coneccion, try in console:
shell> mysql --host=remote.example.com --port=3306 //3306 is the
defaul port for MySQL
http://dev.mysql.com/doc/refman/5.0/en/connecting.html
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