Question: Warning: mysqli_query () expects parameter 1 to be mysqli

  Tags: ,
I have the following code
<?php
function consulta () {

global $conexion; 

$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$bd = "alumnos";
$conexion = mysqli_connect($dbhost, $dbuser, $dbpass, $bd);

$result = mysqli_query('SELECT * FROM alumnos', $conexion);

// comienza un bucle que leerá todos los registros existentes
while($row = mysqli_fetch_array($result)) {
// $row es un array con todos los campos existentes en la tabla
    echo "<hr>";
    echo "clave del alumno: ".$row['claveAlumno ']."<br>";
    echo "Nombre: ".$row['nombre']."<br>";
    echo "Apellidos: ".$row['apellidos']."<br>";
    echo "Fecha de Namiciento:".$row['fNacimiento']."<br>";

} // fin del bucle de instrucciones
mysqli_free_result($result); // Liberamos los registros
mysqli_close($conexion); // Cerramos la conexion con la base de datos
echo "<hr>";

}
echo consulta();

?>

but unfortunately it shows me the following errors

Warning: mysqli_query () expects parameter 1 to be mysqli, string given in C: \ xampp \ htdocs \ connectionMySQL \ resources \ actions \ conexion.php on line 12

Warning: mysqli_fetch_array () expects parameter 1 to be mysqli_result, null given in C: \ xampp \ htdocs \ connectionMySQL \ resources \ actions \ conexion.php on line 15

Warning: mysqli_free_result () expects parameter 1 to be mysqli_result, null given in C: \ xampp \ htdocs \ connectionMySQL \ resources \ actions \ online.php 24

Could you please help with this error?

Solution for mysqli_query () expects parameter 1 to be mysqli

mysqli_query takes connection  as first parameter and then the query and you are doing the opposite, it should be

$result = mysqli_query($conexion,'SELECT * FROM alumnos' );

LEAVE A COMMENT