Warning: mysqli_query() expects Parameter 1 to be mysqli, integer Given

Asked

Viewed 1,289 times

1

I have this code below:

<?php
$conecta_no_banco = require_once ('conecta_db.php');
$login = $_POST['login'];
$senha = $_POST['senha'];
$sql = mysqli_query($conecta_no_banco,"SELECT usuario FROM gerenciador_de_socios.autenticacao_usuarios") or die("Erro!");
$row = mysqli_num_rows($sql);
if(!$login || !$senha) {
    echo "Você deve digitar sua senha e login!";
    exit;
}

if ($row > 0) {
    echo "OK!";
}
mysqli_close($conecta_no_banco);
?>

When I run, it gives the error:

Warning: mysqli_query() expects Parameter 1 to be mysqli, integer Given

What I’m doing wrong?

  • 1

    This is one of the most frequently asked questions about PHP and the error itself tells the reason.... https://answall.com/questions/28184/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in, https://answall.com/search?tab=votes&q=expects%20parameter%20given%20%5bphp%5d, the problem is still on the line depending on the $conecta_no_banco, that this omitted in the code, he is the problematic.

  • @Inkeliz in this case would have to see what it has in conecta_db.php. In conecta_db.php, for your code to work, it must have something at the end like return $variavel_de_conexao

  • 1

    Now that I’ve noticed that, maybe that’s the problem, but there’s no way to know.

  • I have never done anything like this, when I give a require_once, I usually use the functions and variables created in the "child" file (which comes from require_once) in the "parent" file, if Return is omitted the value that returns is an integer (1) if the file exists.

1 answer

2


In this code you have, remove the line:

$conecta_no_banco = require_once ('conecta_db.php');

and changes to

require_once ('conecta_db.php');

and inside the archive conecta_db.php change your connection code to something like this:

$conecta_no_banco = mysqli_connect("127.0.0.1", "usuario", "senha", "banco");
  • It worked perfectly buddy. Thank you very much!

Browser other questions tagged

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