I have a database in a website called booksiders.com and then I have a new website called kryptotech.co.in in which i am looking to use the database of the first website. So how can connect with the database which exists on another hosting server.
This is the code i am using in kryptotech.co.in for connecting to the database of booksiders.com from kryptotech.co.in which is hosted on another server.
<?php
$con = mysql_connect("booksiders.com","bookside","******");
if(!mysql_select_db("bookside_kryptoDB",$con))
echo "Unable to connect to database";
?>
Please tell me what hostname should be used for doing this.
You will have to allow your server IP in allow remote host access list on remote server and ask them to allow port 3306 in their firewall so that you can connect mysql databases from your hosting server.
Related
I am trying to access to the database of my live website from localhost. My website is working on cpanel hosting.
I created database and added user to that database but can not connect to this database from my localhost .
this is the code of database information
<?php
$conf['dbuser']='admin_root';
$conf['dbpass']='rootroot!##$';
$conf['dbname']='bsaiiian_os';
$conf['dbhost']='example.com';
$conf["title"]='DEMO';
?>
I think the problem is from $conf['dbhost'] variable where I'm putting the url of my site and not sure if that is right.
When I'm uploading my script to the hosting and put
$conf['dbhost']='localhost';
the connection is established .
this is error message:
Connection failed: No connection could be made because the target machine actively refused it.
Due to security reasons cPanel's MySQL requires that you allow your IP in order to have access.
This is done through:
cPanel -> Remote MySQL Connection
You need to navigate there and allow your local computer's IP in order to make the connection.
Side Note: This stands true for all IPs, even the server's one that your account is hosted on. You will see your cPanel account's IP already present in there - this is to allow access to MySQL for any files from your cPanel account
I'm trying to connect to a remote database on a server which is accessed through cPanel.
I created a user name and associated it with a database. I'm using:
I'm confused on the host name to use. I tried using the Main Domain name in the left menu panel in cPanel with the port number 3306 but it wouldn't work. I used the shared IP as well with the port number that that wouldn't work as well. I have added my local machine IP to the remote databases page in the cPanel as was told in a post but finally I'm not able to connect to the database.
On echoing the mysql_error(), I get:
Can't connect to MySQL server on 'host_name' (4)
Any help would be great!
your hosting site will specify which name should be used for the host
in hostinghood.com they says that to use localhost itself as host name
so check what your hosting site says about it
I want one website on one server and another website on another server, but only 1 database for both using php and mysql.
is it possible? if yes then how?
Yes. its possible. Normally you dont put your db on distant server. You should keep the db server on same data center so you avail high speed internal network link.
If your websites are in host web1 and web2 and database is in dbhost1, then in web1 and web2 connect to mysql with dbhost1 as host name.
mysqli
$mysqli = new mysqli("dbhost1", "user", "pass");
PDO
$dbh = new PDO('mysql:dbname=dbname;host=dbhost1', "user", "pass");
Legacy mysql extension
mysql_connect("dbhost1", "user", "pass");
Note: Make sure in the database user#web1 (on host web1) or user#web2 (on host web2) has access.
You can connect to a remote database given the correct settings.
Failing that, you could write a service layer that could be called from both servers.
while connecting to mysql database use same database connection credential on both servers.
Yes why not. But for security and performance issues i wouldn't do that.
The question is what do you understand under on another server is the server direct connected over LAN or is the server in another Data center. When the server is in another Data center you can get a lot of traffic and performance issues.
When the server is direkt connected you can change the my.cnf and change the line:
bind-address 127.0.0.1
then the server is reachable from outside. And you should give the user enough rights to connect from outside.
yes, it's possibile.
you have to use a mysql server which is reachable from both servers. and you simply connect with the same host/user/pass from both servers:
define("WEBDOMAIN", "94.145.22.15"); //some fake data
define("DEFDBNAME", "my_db");
define("DEFUSERNAME", "my_user");
define("DEFDBPWD", "my_pass");
mysql_connect( WEBDOMAIN, DEFUSERNAME, DEFDBPWD );
mysql_select_db( DEFDBNAME);
That should be enaugh. You coud have some problems if your hosting providers doesn't allow servers to connect to external servers (sometimes ports are closed).
For security reasons it is common, that You can't connect to a mysql server that has not authorized your hosting server.
So in mysql, You have to allow a user to connect not only from localhost, but also from other host (if You have enought priviliges, You can do it from phpMyAdmin by editing user priviliges afair).
I have an online reservation booking system (php script) that uses a mySQL database. Part of the script is a back end admin panel for offline reservations.
Is it possible to run a service like XAMPP using local host to access the remote database.
You can connect to remote database by having remote host, db username, db password.
Host name = (use the db server IP address)
Database name = (cpanelUsername_databaseName)
Database username = (cpanelUsername_databaseUsername)
Database password = (*)
MySQL Connection Port = 3306 (check your)
If you are using cPanel then you need to allow your local IP for DB access first.
Login to cpanel, on the main menu of CPanel,
Jump down to "Databases" and select "Remote MySQL"
Now add your IP address, or IP range with a wildcard such as 12.34.%
Good Luck
Yes. You need login credentials for the remote database as well as it's port and server address (hostname or IP), as you'd expect. The remote host also needs to have permissions granted for that particular user to access the database remotely, which users will not have by default.
Yes it is. Just the way you connect your local database, you can connect to a remote database with valid credentials. Then only thing changes is the hostname parameter.
for an example if your database is hosted on dreamhost, they have hostnames like..mysql.yourdomain.com. Create a database on your remote server and connect to it as
<?php
mysql_connect('mysql.yourdomain.com','username','password');
i want to connect hosted server database through local server here is my code
<?php
$con=mysql_connect("myserverDbHostname","mydatabaseUsername","Password");
if($con)
{
echo "connect";
mysql_select_db("DatabaseName");
else
{
echo "not connect";
}
?>
when i run this file in local server (xammp server) it could n't be connect i get
Warning: mysql_connect() [function.mysql-connect]: Can't connect to
MySQL server on
i get "not connect" response
can any one guide me
Thanks for advance.
There a three things you need to connect to a remote database:
port 3306 open on the firewalls. Firewalls in server and client must open port 3306!
in my.cnf bind-address = 0.0.0.0 to let mysql bind to all interfaces
sufficient privileges in the database to allow remote connections
Virtual all hosting companies close port 3306 on the firewall, and do not allow direct remote access. And even if they do, you won't get privileges to connect to a database.
Only if the remote database is in your LAN, or you are using a VPS with root access you can configure things to make a remote connection.