Undefined function mysqli_connect ()

Asked

Viewed 36 times

-3

I’ve tried php.ini, reinstalling php on the computer, reinstalling xampp to "activate mysqli", but nothing works and my online host does not allow php lower than php 7.4.

Error presented:

Fatal error : Undetected error: call for undefined function mysqli_connect ().

<?php
$servidor = "localhost";
//$usuario = "marcelo";
//$senha = "123";
$usuario = "root";
$senha = "";
$dbname = "dams";

//Criar a conexao
$conn = mysqli_connect($servidor, $usuario, $senha, $dbname) or die("Falha na conexao: " . mysqli_connect_error());

  • "I have tried several ways to activate the supposed "mysqli"", what were those ways?

  • @Woss Mexi in php.ini, I changed some things reinstalled php on the pc that offline. On the online system I made no changes.

1 answer

-3


To work with PHP 7.0+ try to change the connection to the following format:

<?php
$servidor = "localhost";
$usuario= "user";
$senha = "pass";

// Criar conexão
$conn = new mysqli($servidor, $usuario, $senha);

// Verificar se conectou
if ($conn->connect_error) {
  die("Erro: " . $conn->connect_error);
}
echo "Conectado com sucesso";
?>

As documented here: https://www.php.net/manual/en/function.mysqli-connect.php

Or change your connection to use Pdomysql:

<?php

    $usuario = 'user';
    $senha = 'pass';

    try {
    $conn = new PDO('mysql:host=servidor;dbname=banco', $usuario, $senha);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    } catch(PDOException $e) {
        echo 'Erro: ' . $e->getMessage();
    }
?>

As directed here: https://www.php.net/manual/en/ref.pdo-mysql.connection

  • tried, but still the error persists

  • Edit the question then put your php.ini... and look if there are no more errors in the XAMP log as well...

Browser other questions tagged

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