Use variable in 2 php files

Asked

Viewed 106 times

0

I have a small problem trying to use 1 variable that comes from another php file. Ex: I have a connection file where I have all the data on the database, but in the insert file I need to use one of the variables of the connection file in the function mysqli(); how do I use this variable in other files as a 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;
} 
?>

1 answer

2


Just do it like this:

Filer1.php

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

Filer2.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;
} 
?>
  • I tried it this way but I still can’t, I’ll send the code.

  • I’ve already changed your code.

  • I’ve already changed your code.

  • Obg Peter, I was watching and noticed that the mistake was silly, I was not connecting and not even choosing the bank. I think the sleep started to disturb, rs !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.