Last active
April 5, 2017 03:05
-
-
Save cesc1989/b8b5f19702db16a98eb6 to your computer and use it in GitHub Desktop.
conect to a database and query it to return data in json format
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 | |
$numero_cedula = $_GET['cedula']; | |
//CONEXION A LA BASE DE DATOS | |
$username = "root"; | |
$password = "root"; | |
$hostname = "localhost"; | |
$link = mysql_connect($hostname, $username, $password); | |
if (!$link) { | |
die('Could not connect: ' . mysql_error()); | |
} | |
//SELECCIONAR BASE DE DATOS | |
$db = mysql_select_db("qhp", $link); | |
if (!$db) { | |
die ("No se puede usar la base de datos" . mysql_error()); | |
} | |
// HACER CONSULTA A LA TABLA DE AFILIADOS | |
$query = "SELECT first_name, last_name, uid, validity, typeofmembership FROM users WHERE numdoc='$numero_cedula'"; | |
$result = mysql_query($query); | |
if (!$result){ | |
die("Consulta invalida " . mysql_error()); | |
} | |
$array = mysql_fetch_row($result); | |
echo json_encode($array); | |
// else{ | |
// while ($row = mysql_fetch_assoc($result)) { | |
// echo $row['first_name']; | |
// echo $row['last_name']; | |
// echo $row['uid']; | |
// echo $row['validity']; | |
// } | |
// } | |
// CERRAR LA CONEXION LUEGO DE HACER TODAS LAS OPERACIONES | |
mysql_close($link); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment