How to resolve Fatal error: Call to Undefined Function mysqli_connect() in

Asked

Viewed 98 times

0

Good morning, my site is not working and gives the error Fatal error: Call to Undefined Function mysqli_connect() in /home2/amttli84/public_html/conexion.php on line 7

The strange thing is that on my localhost it works perfectly and is the same on the server. I’ve tried changing php.ini, restarting the server and I don’t know what else to try. Follow the connection code.php

<?php
define('DB_HOST', (getenv('DB_HOST')  ?: '127.0.0.1'));
define('DB_USUARIO', (getenv('DB_USUARIO') ?: 'root'));
define('DB_SENHA', (getenv('DB_SENHA') ?: '1234'));
define('DB_NOME', (getenv('DB_NOME') ?: 'amtt'));

$conexao = mysqli_connect(DB_HOST,DB_USUARIO,DB_SENHA,DB_NOME)
    or die ('Não foi possivel conectar'); <?php

https://prnt.sc/xr9kl5

And the login file is

    session_start();
    include('conexao.php');
    require_once "recaptchalib.php";
    //se um ou ambos dos campos estiverem vazios, retorna ao index
    if(empty($_POST['usuario']) || empty($_POST['senha'])){
        header('Location: index.php');
        exit();
    }

    $secret = "6LdgJ70UAAAAAAQrtJVIRpZiMlZhkEV_0owP3i_C";

    $response = null;
    $reCaptcha = new ReCaptcha($secret);

    if ($_POST["g-recaptcha-response"]) {
        $response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
    }

    if ($response != null) {
        //As variaveis recebem os dados vindos através do POST
        $usuarioLogado = mysqli_real_escape_string($conexao,$_POST['usuario']);
        $senha = mysqli_real_escape_string($conexao,$_POST['senha']);

        //Busca no banco de dados se a senha e usuário informado combinam com algum registro
        $query= "select usuario_id, nivel_acesso from usuario where usuario = '{$usuarioLogado}' and senha = md5('{$senha}')";
        $result = mysqli_query($conexao,$query);
        $row = mysqli_num_rows($result);

        $resultadoFull = mysqli_fetch_assoc($result);

        if($resultadoFull['nivel_acesso'] == 'sus'){

            $_SESSION['usuarioSuspenso'] = true;
            header('Location: index.php');
            exit();
        }else

        //verifica se a senha e usuario informados estao corretos
        if($row == 1){
            $_SESSION['usuarioLogado'] = $usuarioLogado;
            $usuarioLogado = $_SESSION['usuarioLogado'];
            $query2 = "select * from usuario where usuario = '{$usuarioLogado}'";
            $result2 = mysqli_query($conexao,$query2);
            $rows = mysqli_fetch_assoc($result2);

            $_SESSION['nomeServidor']=$rows['nome'];
            $_SESSION['idServidor']=$rows['usuario_id'];
            $_SESSION['nivel_acesso']=$rows['nivel_acesso'];



            $administrador=$rows['administrador'];
            if($administrador =='sim'){
                $_SESSION['adm']=true;
            }else if($administrador =='vcg'){
                $_SESSION['vcg']=true;
            } else{
                $_SESSION['usuarioNormal']=true;
            }



            header('Location: painel.php');
            exit();
        } else {
            $_SESSION['nao_autenticado'] = true;
            header('Location: index.php');
            exit();
        }
    }else {
        echo $response;
        $_SESSION['captchaInvalido'] = true;
        header('Location: index.php');
        exit();
    }


  [1]: https://i.stack.imgur.com/uD2X9.png

1 answer

1


The server you are running the code from does not have the module php_mysqli installed/enabled.

Following answers of this post, if you are using linux (Ubuntu, Mint, debian) just run the following command on the server will resolve:

sudo apt install php-mysqli

In the php installation folder look for the file php.ini and edit the line:

; extension=mysqli (commented/deactivated)

for

extension=mysqli (active)

Note: There are also some tips on php documentation (in English) and at this link.

The way the module is configured also depends on the version of your PHP and which operating system you are using, in case the above changes do not solve I suggest searching how to activate or install the module php_mysqli for your PHP version and your specific operating system.

Browser other questions tagged

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