Warning: mysqli_query () expects parameter 1 to be mysqli

6

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 \ connectionion.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 \ conexion.php on line   24

Could you please help with this error.

    
asked by Rodrigo Arenas 28.09.2017 в 06:15
source

1 answer

5

At first glance, mysqli_query wait as parameters first the connection and then the query and you are doing the opposite, it should be

$result = mysqli_query($conexion,'SELECT * FROM alumnos' );
    
answered by 28.09.2017 / 06:19
source