Connecting to remote MySQL server using PHP
- firewall of the server must be set-up to enable incomming connections on port 3306
- you must have a user in MySQL who is allowed to connect from
%
(any host) (see manual for details)
The current problem is the first one, but right after you resolve it you will likely get the second one.
Remotely connecting to a MySQL database
Use the supplied domain name ukld.db.5510597.hostedresource.com
Prepending the hostname with an IP as you are doing only changes the hostname and that is why it is failing to connect.
The hostname will be converted to an IP address behind the scenes for you. No need to do it yourself. Plus, hardcoding IPs is bad practice as they can change over time.
Remotely connecting to a MySQL database using PHP PDO
You need to remove http from the host and put the port number under port attribute.
Please try with this line :
$dbhost = "mysql:host=10.75.225.171;port=3601;dbname=apt";
PHP - can not connect to remote mysql database
Possible, that your $username
do not have permissions to connect to database from server, where the PHP script is executed.
Try to create a user with permission to connect from remote server. Execute on MySQL server:
CREATE USER 'testuser'@'fh24-219.cybersales.cz' IDENTIFIED BY 'mypass';
Change 'fh24-219.cybersales.cz'
to PHP server IP. If you will write '%'
as server IP it will be accessible from anywhere (it is not recommended).
Updated:
If you do not know what permissions user have, execute SHOW GRANTS;
on for e.g. PhpMyAdmin to see if remote IP is mentioned.
PHP not connecting to Remote MySQL
Found this to be an issue with SELinux that is not allowing httpd network connections.
Executing:
setsebool -P httpd_can_network_connect=1
Solved the problem.
Related Topics
Single Quotes or Double Quotes for Variable Concatenation
How to Schedule the Execution of a PHP Script on the Server Side
Caching Http Responses When They Are Dynamically Created by PHP
Calculate Difference Between Two Dates Using Carbon and Blade
Destroy PHP Session on Closing
Is It Necessary to Declare PHP Array Before Adding Values with []
Why Are "Echo" Short Tags Permanently Enabled as of PHP 5.4
Sort an Array by a Child Array's Value in PHP
Laravel Eager Loading with Limit
Get Last Insert Id After a Prepared Insert with Pdo
Is It Okay to Use Array[Key] in PHP
Get Element by Classname with Domdocument() Method
How to Get a Div Content in PHP
Form Input Field Names Containing Square Brackets Like Field[Index]