I am trying to use PHP to do queries for a Android App I am creating however I am having problems with the nested quotes that I have when calling my code. Let me show you what I am trying to do My php code is as followed:
<?php
$theQuery = $_POST['query'];
if(sizeOfArray == 0){
$clause = "";
}
$con = mysql_connect("localhost" , "localuser" , "NOTMYPASSWORD");
if(!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("localuser_MyApp" , $con);
$result = mysql_query($theQuery);
while($row = mysql_fetch_assoc($result)){
$output[] = $row;
}
print(json_encode($output));
mysql_close($con);
?>
This is the String literal that I am using in Java. I am passing this String to PHP through the POST method. However this query doesn't work because of the single quotes in the where clause.
"SELECT I.id , I.name, I.price
FROM Item I
INNER JOIN Item_Menu IM ON I.id = IM.itemid
INNER JOIN Menu_Type MT ON MT.id= IM.menuid
WHERE MT.name='entrees'";
I tried using the following but this also doesn't work. I get a warning about how the result returned was not a proper SQL result.
"SELECT I.id , I.name, I.price
FROM Item I
INNER JOIN Item_Menu IM ON I.id = IM.itemid
INNER JOIN Menu_Type MT ON MT.id= IM.menuid
WHERE MT.name=\"entrees\"";
If I use an id instead or remove the WHERE clause instead of using an actual String value then the query works fine.
My questions is how can I format this query correctly in java so I can pass it to php properly? More information can be provided if necessary but I didn't want to overload this question with blocks of code.