Im trying to connect with my local database server when im in his network, but i can’t do it. i’m doing the same way im doing for the remote database of infinity free.
with the try method it doesn’t give me any error but if i apply when put when i change like this:
$conn_sv = new mysqli(host, username, password, database);
the error is this: Fatal error : Uncaught mysqli_sql_exception: Connection timed out in /home/vol15_7/infinityfree.com/if0_38157389/htdocs/Classes/connect.php:215 Stack trace: #0 /home/vol15_7/infinityfree.com/if0_38157389/htdocs/Classes/connect.php(215)
when i’m simulating the database as localhost i can connect to the my server, but when i upload the file to infinity i cant.
the server accepts external connections from others pc softwares so it should be able to allow external connections from the website, right?
when i simulating and i change the infinity database to localhost, i can connect with my physical server too.
Not necessarily. If the other software is on the same PC as the database, or on the same network, this is often considered a local connection, depending on how the database is set up.
Your infinity free website on the otherhand, is trying to connect from the infinity free servers to your server (even if your pc is on the same network, unless your connecting using java script? Remember, PHP runs on the infinity free server, Javascript runs in the viewers browser) So this is an external connection.
So if your database doens’t accept conections from external IP’s this will be blocked.
You also need to make sure that your server is visible from the internet. So you may need to set up port forwarding on your router, and have either a domain name pointing to your server or an external static IP pointing to it.
Hosting your own server for access from the web isn’t always as simple as it looks. Thats why I use Infinity free rather than hosting on my own server lol.
Which “external connections” have you tested exactly?
Connections from other software on the same PC don’t count. Connections from other PCs on the same network also don’t count, because they can connect over the internal network.
For most home networks, you’ll probably need to configure port forwarding in your router so that the MySQL port 3306 is forwarded to the PC that runs the database connection. And in the connection details on your website with us, you need to then enter the external IP address of your home, not the internal IP of the PC running the database server.
To test if it really works externally, you should try to connect from somewhere outside of the same home network. Even connections to the external IP address of your home from within your home are often handled by special logic in your router (hairpin NAT), and don’t go over the public internet.