call of a function from another php file

2

$bd= new DB();
$conectar = $bd->conectar();
function extFolio($folio)
{
    $query = "select FolioParticipanteCG from participantes where FolioParticipanteCG = '".$folio."'";
    $folio=mysqli_query($conectar,$query)or die("Error al seleccionar folio".mysqli_error());//En esta linea es donde me genera el error 
    $folio=mysqli_num_rows($folio);
    return $folio; 
}

This is the error Undefined variable: connect I'm new to php so I think it's because the connect variable I need to instantiate within the function but I would like to use it globally and that same function is in another php file which is called clas_conex.class.php but I do not see the problem anymore What do I do? I would appreciate your help or any opinion.

    
asked by Emmanuel Torres 07.06.2018 в 20:26
source

1 answer

2

If the variable $conectar is in a file, conexion.php for example:

<?php
$dbServername = "localhost";
$dbUsername = "username";
$dbPassword = "pw123";
$dbName = "database";

$conectar = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
?>

You can use it with a include of that file and thus use it from others:

function extFolio($folio)
{
    include 'conexion.php';
    $query = "select FolioParticipanteCG from participantes where FolioParticipanteCG = '".$folio."'";
    $folio=mysqli_query($conectar,$query)or die("Error al seleccionar folio".mysqli_error());//En esta linea es donde me genera el error 
    $folio=mysqli_num_rows($folio);
    mysqli_close($conectar);
    return $folio; 
}
    
answered by 07.06.2018 в 20:38