MySQL Forums
Forum List  »  PHP

MySQL to json
Posted by: Alex Navarro
Date: April 05, 2014 02:23AM

Hey guys, on my server I´ve got a PHP file that retrieves my SQL database and encodes it to JSON:

<?php


$host = "abc"; //Your database host server
$db = "abc"; //Your database name
$user = "abc"; //Your database user
$pass = "abc"; //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);
}


}


?>


Im currently developing and iOS app.. anyways.. i´ve populated my database with three objects.. so far so good.. everything works like a charm.. when i go to my php file that is online it shows correctly (as json).. but when i add more objects and update my php file that is online i only get a blank screen.. like it isn't encoding at all.. any ideas? is it just my slow internet server or could it be something else?? hope u understand what i mean :( thanks for now


btw I'm using phpmyadmin..

Options: ReplyQuote


Subject
Written By
Posted
MySQL to json
April 05, 2014 02:23AM
April 07, 2014 10:59AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.