Use variable in 2 php files

0

I'm having a little problem trying to use 1 variable that comes from another php file. Ex: I have a connection file where I have all the data about the database, but in the insert file I need to use one of the connection file variables in the mysqli () function; how do I use this variable in other files as an extend for example?

<?php 

$server = "127.0.0.1"; 
$banco = "Crud"; 
$usuario = "root"; 
$senha = "";

$conexaoDB = mysqli_connect($server, $usuario, $senha); 
$conexaoDB = mysqli_select_db($conexaoDB,"$banco");
if (!$conexaoDB) {
    echo "Erro, não foi possível conectar-se ao banco de dados"; exit;
} 
?>
    
asked by anonymous 06.06.2016 / 08:39

1 answer

2

Just do it like this:

  

File1.php

<?php 
$server = "127.0.0.1"; 
$banco = "Crud"; 
$usuario = "root"; 
$senha = "";
?>
  

File2.php

<?php
include 'Ficheiro1.php';
$conexaoDB = mysqli_connect($server, $usuario, $senha); 
$conexaoDB = mysqli_select_db($conexaoDB,"$banco");
if (!$conexaoDB) 
{
  echo "Erro, não foi possível conectar-se ao banco de dados"; 
  exit;
} 
?>
    
06.06.2016 / 08:45