Connecting Local Host to online sql database - php

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

Related

MySQL database IP address from rackspace or google cloud?

Ok here’s the deal. I setup MySQL database on Rackspace and I’m trying to connect to it. I am using the tutorial google maps to create store locator using MySQL. The line of the code in the tutorial asks for the host name and I’m giving the IP address of my server on Rackspace. I’m using what I think is the correct one but it’s not working. Any ideas?
Here's the google tutorial code:
// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
};
My code:
$connection=mysqli_connect ('THE IP ADDRESS OF MY RACKSPACE SERVER', 'MY USERNAME', 'MY PASSWORD');
Here's a link to the tutorial from google: https://developers.google.com/maps/solutions/store-locator/clothing-store-locator
I know I have the server IP correct and my username/password correct since I'm able to login via SSH from terminal with those credentials.
When I use mysql> \s to show the status it says Connection: Localhost via UNIX socket - does this mean it's local host? I need it hosted on IP to connect right?
I expect that your MySQL server is by default by your Linux distribution's packaging configured to listen either locally, or on the socket file only. You can update your DB config to listen on the public IP address of your server however obviously this can come with some security implications.
To do this edit the /etc/mysql/mysqld.conf file (this may be in a slightly different location depending on distribution being used) and the following line as such...
From
#bind-address = 127.0.0.1
To
bind-address = 0.0.0.0
Now restart your MySQL service using the systemctl or service command.
service mysql restart
Your MySQL server is now listening on ALL the host's IP addresses. If you want to limit it to just one you should enter that IP instead of 0.0.0.0. You should now be able to connect to your MySQL server remotely, however, you must have already configured your database user to be able to login from the webserver. If you haven't configured the user yet do something like this.
mysql
CREATE USER '<username>'#'<webserver ip address here>' INDENTIFIED BY '<password>';
GRANT ALL PRIVILEGES ON <database>.* TO '<username>'#'<webserver ip address>';
FLUSH PRIVILEGES;
You should now be able to login as this user and view / modify / insert etc... data to the database specified from the server IP address specified. You can test this from the web server using the MySQL client like this...
mysql -u <username> -h <db server ip> -p

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

PHP can't connect to the MySQL Database Access denied

I get this error message
Access denied for user 'user'#'localhost' (using password: YES)
I tried to access with the root, the admin account and some user account I made for the web visitors with a few privileges. Those users (admin and web user) were created with cPanel.
I'm testing the connection with this simple code to avoid making a mess with functional code.
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>
I stumbled with this explanation but it doesn't work either
Your cPanel username and password can be used to connect to your databases (as well as your cPanel). If you're connecting to your database using your cPanel username and password, you can reset your cPanel password to ensure you are using the correct username and password.
If you setup a MySQL username and password specifically for accessing a database, you'll want to ensure you are using the correct username in your php scripts. For example, MySQL usernames are always in this format:
cpanel-username_mysql-username
If your cPanel username is userna5 and you created a database username of dbuser1, then the actual database username would be:
userna5_dbuser1
Edit: i already assigned the users to a database and their privileges. I'm working on a remote server
I faced the exact same issue on one of my employees' Windows PC.
The issue was caused duo the fact that his private repositories folders including those who were used by Docker were located in C:\Users{user_name} folder.
At some point in time, Windows prevented Docker's access to these folders.
Solution: relocation the folders outside the Users folder solved the issue.
Are you running the code on your local machine or on the remote server. If it's running on your local machine you'll have to replace 'localhost' with the ip address of the server eg. '123.123.123.123'
If you are using the online server after creating the user and the database make sure you give the user privilege to access the database
If you are accessing MySQL database from the remote server, you will have to use server IP address for MySQL host. Also you will have to allow your remote server IP address in "Remote MySQL" under your cPanel otherwise you will not be able to access your database remotely.

Remote MySQL database connection using 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

mysql connection from a different domain

I have website example.com, it contains a MySQL server. I have another example.org, both are different domains. I want to access the MySQL server on example.com from example.org. How would it be possible?
You will need to set the remote example.com when you call the database connection initialization function. For example:
mysqli_connect("example.com", 'username', 'password', 'database name');
But you will need to check whether example.com's MySQL server is set to accept connections from other hosts (see the bind-address directive in your my.cnf or my.ini), and that the username you connect with is set to be able to connect from external domains.
Consider the following Users page of phpMyAdmin:
It is clear that only user test has access from outside domains (% in the Host field). Not shown on the image, but user test has full privilege on the database called test. The other users are bound to the local domain, even though the server is set to accept connections from the outside, when authenticating, users are thrown a denial.
You can connect to remote MySQL server. Just have to make sure that the remote server is binding to public address.
Here's how: http://www.howtogeek.com/howto/mysql/switch-mysql-to-listen-on-tcp/
You can connect to any MySQL server wherever it is, as long as it's setup for remote connection.
Depending on your operating system and webserver of choice, the settings will be different, but a good place to start is by (if using linux) looking here:
/etc/mysql/my.cnf
In this file you will find:
bind-address: 127.0.0.1
You will change this to the IP address of the server and then restart the mysql daemon.
..and now you can connect remotely ;)

Categories