-
-
Save fethica/52e2f4f59aa4ed44f859 to your computer and use it in GitHub Desktop.
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 | |
/*************************************************************** | |
Description: City data in JSON. | |
Developer: Vishal Kurup | |
***************************************************************/ | |
$host = "abc12345"; //Your database host server | |
$db = "abc12345"; //Your database name | |
$user = "abc12345"; //Your database user | |
$pass = "abc12345"; //Your password | |
$connection = mysql_connect($host, $user, $pass); | |
//Check to see if we can connect to the server | |
if(!$connection) | |
{ | |
die("Database server connection failed."); | |
} | |
else | |
{ | |
//Attempt to select the database | |
$dbconnect = mysql_select_db($db, $connection); | |
//Check to see if we could select the database | |
if(!$dbconnect) | |
{ | |
die("Unable to connect to the specified database!"); | |
} | |
else | |
{ | |
$query = "SELECT * FROM cities"; | |
$resultset = mysql_query($query, $connection); | |
$records = array(); | |
//Loop through all our records and add them to our array | |
while($r = mysql_fetch_assoc($resultset)) | |
{ | |
$records[] = $r; | |
} | |
//Output the data as JSON | |
echo json_encode($records); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment