php - Connecting to MySQL database hosted on remote server -
Recently I bought a domain "domain.com".
- A database was created with the name "Database 1"
- User added" user1 "database to" database1 "
Li> Username "user1" and password "pass1 User created with "
So far so good.
After this I clicked on PHPMyAdmin and redirected to the PHPMyAdmin webpage. There I see "database 1" which I had created earlier. To click on that database, I used the import to import a very simple table called "test" [column (id, name, surname)]. Importing the table "Test" table is "Database 1", which is correct.
After that I have tried to use the code below from that database ( connect_to_db.php
):
// Make connections $ Con = mysqli_connect ("domain.com", "user1", "pass1", "database1"); // Check connection if (mysqli_connect_errno ()) {echo "failed to connect to MySQL:". Mysqli_connect_error () "& Lt; br & gt;"; }
I uploaded the connect_to_db.php
to / home / domain / public_html /
.
When I try to connect to database 1, I get the following error:
Warning: mysqli_connect () [function.mysqli-connect]: (28000 / 1045): User 'user1' @ Xxx.xxx.xxx.xxx (using password: yes) /home/karkoona/public_html/connect_to_db.php 13 line in
Where xxx.xxx.xxx.xxx
is a public IP domain.com (if I get it right).
In addition to this, I am looking at the right side of PHPMyAdmin's landing page:
User: domain @ localhost
Any ideas Why can not I use the database with the current user? Is there any mistake in my code?
Thank you.
You need a grant to access the User1 IP access to access remote servers:
Allow all authorities on the database. * 'User1'@'xxx.xxx.xxx.xxx' approved by 'Pass 1';
Note: Replace current information like current information like xxx.xxx.xxx.xxx
to existing server IP which will reach remote MySQL.
Since you are using cPanel, you can do this to allow the IP:
- In your cPanel Sign in (if not already logged in)
- Scroll down to the database section.
- Click on the remote MySQL icon.
- Enter the IP address of the computer that has a remote connection.
- Click the Add Host button.
Comments
Post a Comment