MySQLi - Consulta

Sintaxis

mixed mysqli_query (
   mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ])

Definición y uso

Se utiliza para realizar una consulta en la base de datos.

Ejemplo

Pruebe el siguiente ejemplo:

<?php
   $servername = "localhost:3306";
   $username = "root";
   $password = "";
   $dbname = "TUTORIALS";
   $conn = new mysqli($servername, $username, $password, $dbname);

   if ($conn->connect_error) {
      die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
      exit();
   } 
   echo 'Success... ' . mysqli_get_host_info($conn) . "\n";
   
   $stmt = $conn->prepare("INSERT INTO tutorials_auto (id, name) VALUES (?, ?)");
   $stmt->bind_param("is", $id, $name);
   $id = "10";
   $name = "sai";
   $stmt->execute();
   echo "New records created successfully";
   
   $stmt->close();
   
   if ($result = $conn->query("SELECT name FROM tutorials_auto LIMIT 10")) {
      printf("Select returned %d rows.\n", $result->num_rows);
      $result->close();
   }
   
   $conn->close();
?>

La salida de muestra del código anterior debería ser así:

Success... localhost:3306 via TCP/IP New records created successfully Select returned 3 rows.