Consult bank on another server

0

I have a MySQL database and need to query it from another server using PHP. What is the best way to do this?

Is it possible to activate a function on the database server and return it to the query result?

    
asked by anonymous 04.07.2017 / 23:58

1 answer

3

If the mysql server does not have an "inbound" firewall, you can usually access it with mysqli or PDO , just point the mysql server IP address or its host address if you have).

Example with mysqli :

<?php
$nomedoservidor = "mysql.outro-host.com";
$usuario = "username";
$senha = "password";
$banco = "banco1";

$conn = new mysqli($nomedoservidor, $usuario, $senha, $banco);

If it is 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);

I recommend to read:

These posts will help you understand where the Mysql server is, where is PHP, where is Apache and what is Mysql API .

    
05.07.2017 / 00:03