11.09.2018 Views

Aprender a desarrollar un sitio Web con PHP y MySQL

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

echo "Número de personas que tengan <strong>un</strong>a edad > 35:<br />

".mysqli_stmt_num_rows($resultado)."";<br />

//Liberación del resultado<br />

mysqli_stmt_free_result($resultado);<br />

mysqli_stmt_close($resultado);<br />

}<br />

if (mysqli_close($base)) {<br />

echo ’Des<strong>con</strong>exión realizada.’;<br />

}<br />

else {<br />

echo ’Error en la des<strong>con</strong>exión.’;<br />

}<br />

}<br />

else {<br />

printf(’Error %d : %s.’,mysqli_<strong>con</strong>nect_errno(),<br />

mysqli_<strong>con</strong>nect_error());<br />

}<br />

?><br />

Conexión realizada.<br />

Información del servidor:<strong>MySQL</strong> host info: 127.0.0.1 <strong>con</strong> TCP/IP<br />

Número de personas que tengan <strong>un</strong>a edad > 35: 2<br />

Des<strong>con</strong>exión realizada.<br />

g. Examinar los errores de <strong>un</strong>a <strong>con</strong>sulta preparada<br />

Las f<strong>un</strong>ciones que permiten recuperar los errores de <strong>un</strong>a <strong>con</strong>sulta preparada sonmysqli_stmt_errno() y mysqli_stmt_error().<br />

La f<strong>un</strong>ción mysqli_stmt_errno() permite devolver el número de error. Esta f<strong>un</strong>ción toma como argumento el objeto <strong>con</strong>sulta que la<br />

f<strong>un</strong>ción mysqli_prepare() ha devuelto y devuelve 0 si no hay error.<br />

La f<strong>un</strong>ción mysqli_stmt_error() permite devolver el mensaje de error. Esta f<strong>un</strong>ción toma como argumento el objeto <strong>con</strong>sulta que la<br />

f<strong>un</strong>ción mysqli_prepare() ha devuelto.<br />

Estas f<strong>un</strong>ciones muestran los errores <strong>un</strong>a vez que se ejecuta la <strong>con</strong>sulta. Para ver los errores de preparación, utilice las<br />

f<strong>un</strong>ciones mysqli_errno() y mysqli_error().<br />

Por ejemplo, si añade <strong>un</strong>a persona <strong>con</strong> <strong>un</strong> identificador que ya existe:<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!