php error with mysql and mysqli

0

I'm a little new to programming and I'm having a hard time, I was programming a website and I ran it on wampserver, but for a while I updated the wamp version and MYSQL's php commands stopped working, it works only when I change the commands to MYSQLI and even though I'm still giving mtos errors mysqli_query() expects at least 2 parameters, 1 given in ./.../..... or mysqli_error() expects exactly 1 parameter, 0 given in in every select I used, for example:

$variavel = mysqli_query("SELECT * FROM tabela ORDER BY RAND() LIMIT 5") or die(mysqli_error());

The connection part with the bank looks like this:

    header( 'Content-Type: text/html; charset=utf-8' );
    $servidor = "...";
    $usuarioServidor = "...";
    $senhaServidor = "...";
    $nomeBD = "...";

    $conectar = @mysqli_connect($servidor,$usuarioServidor,$senhaServidor) or die ("Não foi possível acessar o servidor");
    $selesionarBD = @mysqli_select_db($nomeBD,$conectar) or die (mysqli_error());

Remembering that when I put MYSQL does not work, only with MYSQLI

Why MYSQL commands are no longer working and why MYSQLI are giving error?

    
asked by anonymous 16.01.2018 / 04:27

2 answers

2

When you use the mysqli_query function, you must pass two attributes : The resource and the query .

if (!mysqli_query($conectar, "SELECT * FROM tabela")) {
    die(mysqli_error($conectar));
}

Already in the mysqli_error function, you should pass only the attribute resource .

This attribute allows the function to identify the connection, which database is selected, etc.

When you work with Object Orientation, this is not necessary.

    
16.01.2018 / 04:45
0

Alessandro Pardo, you should follow the php documentation according to the extension Enhanced MySQL Extension

The query part should look like this:

$variavel = mysqli_query($conectar, "SELECT * FROM tabela ORDER BY RAND() LIMIT 5") or die(mysqli_error($conectar));

The code part of the database should look like this:

header( 'Content-Type: text/html; charset=utf-8' );
$servidor = "...";
$usuarioServidor = "...";
$senhaServidor = "...";
$nomeBD = "...";

$conectar = @mysqli_connect($servidor,$usuarioServidor,$senhaServidor,$nomeBD) or die ("Não foi possível acessar o servidor");
$selesionarBD = @mysqli_select_db($conectar, $nomeBD) or die (mysqli_error($conectar));
    
16.01.2018 / 12:40