Remote MySQL database connection using php - php

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

Related

Connect remotely to cpanel Database with php

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

How to make database connection from different website

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.

Unable to connect to database on cPanel only

I am unable to connect my script to database on my server (cPanel/WHM)
But the script is working on my localhost WAMP
The database is attached correctly other script is working but only this script is not woorkign
Screen SHot
If the database host and host of your application are different: add the ip of your application host to the whitelist (Remote MySQL icon in cPanel)
Check your credentials
Check the privileges of the user

Remote MySQL connection from Godaddy

I am trying to connect to a remote mySQL server from a Godaddy hosting account.
$con = mysqli_connect("xx.xx.xx.xx","username","pass","db_name",'3306');
I am using the above code, but keep getting the following error back:
Can't connect to MySQL server on 'xx.xx.xx.xx' (110)
From the error it seems that it's trying to connect on port 110, even though I have specified 3306 as the port in the PHP call.
If the script resides on the same machine as the mysql server then change the ip address to 'localhost' and since you're using the default port you can drop that as well.
If your script is attempting to connect to a machine outside of your localhost, you may need to allow the ip either via iptables or the remote mysql host within cpanel.

Connecting Local Host to online sql database

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');

Categories