Estilo orientado a objetos
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* "Create table" no devolverá ningún conjunto de resultados */
$mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City");
printf("Tabla myCity creada con éxito.\n");
/* Consulta "Select" devuelve un conjunto de resultados */
$result = $mysqli->query("SELECT Name FROM City LIMIT 10");
printf("Select ha devuelto %d líneas.\n", $result->num_rows);
/* Si tenemos que recuperar muchos datos, utilizamos MYSQLI_USE_RESULT */
$result = $mysqli->query("SELECT * FROM City", MYSQLI_USE_RESULT);
/* Tenga en cuenta que no podemos ejecutar ninguna función que actúe en el servidor mientras
el conjunto de resultados no esté cerrado. Todas las llamadas devolverán un 'out of sync' */
$mysqli->query("SET @a:='this will not work'");
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* "Create table" no devolverá ningún conjunto de resultados */
mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City");
printf("Tabla myCity creada con éxito.\n");
/* Consulta "Select" devuelve un conjunto de resultados */
$result = mysqli_query($link, "SELECT Name FROM City LIMIT 10");
printf("Select ha devuelto %d líneas.\n", mysqli_num_rows($result));
/* Si tenemos que recuperar muchos datos, utilizamos MYSQLI_USE_RESULT */
$result = mysqli_query($link, "SELECT * FROM City", MYSQLI_USE_RESULT);
/* Tenga en cuenta que no podemos ejecutar ninguna función que actúe en el servidor mientras
el conjunto de resultados no esté cerrado. Todas las llamadas devolverán un 'out of sync' */
mysqli_query($link, "SET @a:='this will not work'");
Los ejemplos anteriores mostrarán :
Tabla myCity creada con éxito.
Select ha devuelto 10 líneas.
Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...