Created
April 10, 2018 17:10
-
-
Save danieluyo/b54353cf8082c9a534e4659649d40609 to your computer and use it in GitHub Desktop.
David
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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