Created
March 8, 2015 22:40
-
-
Save manviny/4b353d436f5d30b99665 to your computer and use it in GitHub Desktop.
mysql php
This file contains 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 | |
// Conectando, seleccionando la base de datos | |
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') | |
or die('No se pudo conectar: ' . mysql_error()); | |
echo 'Connected successfully'; | |
mysql_select_db('my_database') or die('No se pudo seleccionar la base de datos'); | |
// Realizar una consulta MySQL | |
$query = 'SELECT * FROM my_table'; | |
$result = mysql_query($query) or die('Consulta fallida: ' . mysql_error()); | |
// Imprimir los resultados en HTML | |
echo "<table>\n"; | |
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
echo "\t<tr>\n"; | |
foreach ($line as $col_value) { | |
echo "\t\t<td>$col_value</td>\n"; | |
} | |
echo "\t</tr>\n"; | |
} | |
echo "</table>\n"; | |
// Liberar resultados | |
mysql_free_result($result); | |
// Cerrar la conexión | |
mysql_close($link); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment