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
Related
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
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.
I was just wondering if it was possible for certain databases to block SQL accesses through mysql_connect. I recently downloaded XAmpp and created a SQL database using my own computer as a local host and wrote a PHP file that accessed that database.
However, when I tried to change the username and host settings so that Xampp would run the PHP files that would then connect to the external SQL database of a free hosting site that I'm trying to use (biz.co.nf), I got the following error message:
Warning: mysql_connect(): Connection refused in /Applications/XAMPP/xamppfiles/htdocs/...
Right now I'm thinking either:
My login credentials to that database are incorrect, or
Somehow the host blocks SQL accesses from external users, but if I were to load my php code into the server using FileZilla, it should work okay?
Please let me know if this is the case.
I'm also fairly certain I have the right login credentials.
Here's what I have:
$host = "fdb13.biz.nf";
$username = "1764941_login";
$password = ________;
$db_name = "1764941_Login";!
$tbl_name = "Members";
//Connect to server
mysql_connect($host, $username, $password)or die("Cannot Connect!");
mysql_select_db($db_name)or die("Cannot select Database");
with my server settings according to my website...
Of course, I omitted my password.
Connections are refused from remote locations to MySQL for security reasons. You can add your IP Address to enable MySQL to listen from your database by following the instructions in this link - Cyberciti biz tips on enabling remote access to mysql database server In your case, add the IP address of the location where your PHP script.
I would also say that
mysql_connect
is deprecated in PHP. Use mysqli instead. Check the comments in the link - PHP original MySQL API
I have two servers, for the sake for my questions, lets name the first server A, and the second server B. Server A is a magento server that has a lot of user data, and server B is a basic web page.
I want to create an analytics dashboard in server B, that uses the SQL databases of server A.
Now the problem is having a remote connection from server B to server A.
I try to connect to server A, using this code in server B:
$servername = "104.2*****"; // Server A
$username = "root";
$password = "******";
$dbname = "magento";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
I get this error:
Connection failed: Can't connect to MySQL server on '104.2******'
Can someone please tell me what I'm doing wrong?
You may need to create a ssh tunnel to connect to a remote server hosted database if the settings on the database server do now allow unsecure connections which is likely why you're getting that error.
http://kb.mediatemple.net/questions/133/Tunnel+local+MySQL+server+through+SSH#gs
It might be that there is a firewall restriction on the server you want to connect to. The MySQL port connection might be restricted.
Try to connect from the server you run this script (or another server) to the ip/port of the server you want to connect to.
If you have access to a linux/windows console, try running:
telnet 104.2***** 3306
3306 is the default port for MySQL and telnet should work.
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