0
I have a Mysql database and need to consult it from another server using PHP. What’s the best way to do this?
It is possible to activate a function on the database server and make it return the result of the query?
0
I have a Mysql database and need to consult it from another server using PHP. What’s the best way to do this?
It is possible to activate a function on the database server and make it return the result of the query?
3
If the mysql server does not have an "input" firewall it can access normally with mysqli
or PDO
, just point to the IP of the "mysql server" or its host address (if).
Example with mysqli
:
<?php
$nomedoservidor = "mysql.outro-host.com";
$usuario = "username";
$senha = "password";
$banco = "banco1";
$conn = new mysqli($nomedoservidor, $usuario, $senha, $banco);
If it’s a "fixed ip":
<?php
$nomedoservidor = "203.40.1.2"; //Exemplo fictício
$usuario = "username";
$senha = "password";
$banco = "banco1";
$conn = new mysqli($nomedoservidor, $usuario, $senha, $banco);
Recommend who reads:
These posts will help you understand where the Mysql server is, where PHP is, where Apache is and what it is Mysql API.
Browser other questions tagged php mysql
You are not signed in. Login or sign up in order to post.
The problem is that the server where I need to use the database data is not accepting PDO. I think probably because of some firewall.
– marcelo2605
@marcelo2605 which error exactly?
– Guilherme Nascimento
ERROR: SQLSTATE[HY000] [2003] Can’t connect to Mysql server on IP ADDRESS
– marcelo2605
@marcelo2605 you have access to the panel to control these external banks?
– Guilherme Nascimento
The mysql access port is the default : 3306? Have you checked if it is on the correct port? Tried to ping the ip of the server where the other bank is via DOS or SHELL?
– Rafael Salomão