Skip to content

Instantly share code, notes, and snippets.

@danieluyo
Created April 10, 2018 17:10
Show Gist options
  • Save danieluyo/b54353cf8082c9a534e4659649d40609 to your computer and use it in GitHub Desktop.
Save danieluyo/b54353cf8082c9a534e4659649d40609 to your computer and use it in GitHub Desktop.
David
<?php
$db = new mysqli('localhost', 'user', 'pass', 'demo');
if($db->connect_errno > 0){
die('No es posible conectar a la base de datos. [' . $db->connect_error . ']');
}
$sql = "SELECT * FROM example";
if(!$result = $db->query($sql)){
die('Existe un error ejecutando la consulta. [' . $db->error . ']');
}
echo 'Total de resultados: ' . $result->num_rows;
while($row = $result->fetch_assoc()){
echo $row['id'] . '<br />';
}
$result->free(); // No olvides liberar memoria
$db->close(); // Y cerrar la conexión
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment