I am creating a script to execute procedures in the database of some clients, I have the following arrays with the credentials of each one:
$hosts["Cliente1"] = array("ip"=> "ip_do_cliente", "usuario" => "usuario","senha" => "12345","base" => "conadmin","porta" => "3306");
$hosts["Cliente2"] = array("ip"=> "ip_do_cliente", "usuario" => "usuario","senha" => "12345","base" => "conadmin","porta" => "3306");
$hosts["Cliente3"] = array("ip"=> "ip_do_cliente", "usuario" => "usuario","senha" => "12345","base" => "conadmin","porta" => "3306");
I make a foreach to connect in each of them, this way:
foreach ($hosts as $key=>$host)
{
$conn = mysqli_connect($host['ip'], $host['usuario'], $host['senha'], $host['base'], $host['porta']);
}
If successful, I'll do a query to save to my database, like this:
$data = date('d/m/Y H:i:s');
$ip_cliente = $host['ip'];
$cliente = ????;
$mensagem = 'Teste Executado com sucesso!';
$query = sprintf("INSERT INTO pbx_teste_permissao(ip_cliente, data_teste, mensagem)"
. "values('%s','%s','%s', '%s')",$ip_cliente, $data, $cliente, $mensagem);
pg_query($query);
I also wanted to store the client name, how could I return the foreach from the client name and populate the $ client variable?