Android : Large MySQL database in android

on Friday, September 26, 2014


So I have successfully created a CRUD ( Create, Read, Update and Delete ) Android APP that successfully connects to a MySQL by using PHP scripts to do so. I have tested that same APP with 3 different small MySQL databases. These databases had 6 columns, 1 which was of course the id. The syze varied from 5 to 50 fields. Also, all my php queries in the browser give the expected JSON response.


So I switched to a larger database ( 1200 fields, 30 columns ) and I immediately had a feeling my query wouldn't fit this case since I was selecting all from the database, putting it into an array then selecting the fields. I tried selecting the desired fields but that didn't work too.


Problem: If I try the query in the browser, it just keeps loading and loading but displays nothing. the commented line was my other try. Of course the app doesn't work as well and returns



Error parsing data org.json.JSONException: End of input at character 0 of .


Query :



$result = mysql_query("SELECT * FROM empresa") or die(mysql_error());
//$result = mysql_query("SELECT marca,investimento,marcatotal,dataconstituicao,datainicio FROM empresa") or die(mysql_error());


get_all.php



header('content-type: application/json; charset=utf-8');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_results=utf8');

if (mysql_num_rows($result) > 0) {
$response["empresa"] = array();

while ($row = mysql_fetch_array($result)) {
$product = array();
$product["eid"] = $row["eid"];
$product["marca"] = $row["marca"];
$product["investimento"] = $row["investimento"];
$product["dataconstituicao"] = $row["dataconstituicao"];
$product["datainicio"] = $row["datainicio"];

array_push($response["empresa"], $product);
}
$response["success"] = 1;

echo json_encode($response);


So I changed this query, which worked with previous databases with this query ( which didn't work in the past with the small databases but displayed the correct json response but displays the correct JSON response in the browser).


get_allv2.php



$sql="SELECT eid,marca,investimento,marcatotal,dataconstituicao,datainicio FROM empresa" ;

header('content-type: application/json; charset=utf-8');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_results=utf8');

$rs = mysql_query($sql,$conn);

while ($row=mysql_fetch_assoc($rs))

{
$i=0;
foreach($row as $key => $value)
{
if (is_string($key))
{
$fields[mysql_field_name($rs,$i++)] = $value;
}
}
$json_result [ ] = $fields;
}

$response = json_encode($json_result);

print_r($response);


The logcat error, however, is different in this query:



Error parsing data org.json.JSONException: Value [{"marca":"4 Ingletes","datainicio":"ND","datac.... "my data continues.. .


So my guess is, my JSONParser.java and DisplayAll.java are not reading the JSON array correctly even though they worked with a small database. And my old .php query worked with the small database but doesn't work correctly in this one. Any idea why this might be happening? ( I didn't want to make this very long so I did not include the JSONParser.java and DisplayAll.java .I can edit this and include it if anyone thinks it will help! ).


Thanks in advance for any help provided


0 comments:

Post a Comment