How can I connect from one website to database of another website in php.
You add the connection details in config.php
or where you store them, and another-website.com
or the IP to the host url (You probably have localhost
there), then the username and the password.
The other website will require their port to be open for yours to connect to. They will also need the database user to allow connections that are not just from the local machine.
If you have a fairly standard LAMP set-up, this will mean opening port 3306 on the database server so outside connections can be made, and a database user setting up that will be able to connect from the outside world.
Bear in mind their may be latency issues.
Just swap (what I presume you are using) localhost to the address of the database on the other server.
eg mysql.mywebsite.com
You need to know where the other website's database server is located, and you'll need to be able to connect to the database from remote sources at some designated port. Once you're sure you know all those, as well as the login credentials, you can just connect as you would normally do your own database.