Android Question call MySql stored procedure with ExecuteRemoteQuery

achtrade

Active Member
Licensed User
Hello,

I have a stored procedure in MySQL, it receives 2 parameter and return an integer value.

How can I call this SP using ExecuteRemoteQuery and catch the returned value.

I'm using ExecuteRemoteQuery because my db is hosted in Godaddy.

thanks.
 

achtrade

Active Member
Licensed User
I solved this removing the output parameter from the sp and now it only return a single value using select statement. Now I need to extract that value from here
B4X:
parser.Initialize(res)
Result = parser.NextArray
I did this but I'm not sure if this is the correct way

B4X:
Result = parser.NextArray 'returns a list with maps
Dim m As Map
m = SPResult.Get(0)
Msgbox("Result=" & m.Get("Result"),"")
A little help with this

thanks.
 
Last edited:

DonManfred

Expert
Licensed User
Missed your answer

Just saw the link to the php...

You log output does not look like a map.

see this for an example log output how a map should look like

B4X:
    Dim m As Map = CreateMap("Month":1,"Result":10)
    Log(m)
        ' (MyMap) {Month=1, Result=10}
So i believe your "m" is NOT a Map.

Your output looks like a json string with two values (not a map)
the values are "Result" and "-1"

As the original php is not retrieving any results from a stored procedure i suggest to post the php-file you are USING (you can put xxx on the credentials as we dont need them)

maybe the "-1" IS the result?! ;-) (-1 in php is TRUE)
 
Last edited:

achtrade

Active Member
Licensed User
Manfred,

The php is the same, I didn't change it at all

PHP:
$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());mysql_select_db($databasename) or die(mysql_error());mysql_query("SET CHARACTER SET utf8");$query = file_get_contents("php://input");$sth = mysql_query($query);

if (mysql_errno()) {header("HTTP/1.1 500 Internal Server Error");
 echo $query.'\n';
 echo mysql_error();
}
else
{$rows = array();
 while($r = mysql_fetch_assoc($sth)) {$rows[] = $r;
 }
 print json_encode($rows);
}?>
inside my MySQL SP I have a select statement like this: select '-1' as 'Result';

and this is how I call the SP

B4X:
ExecuteRemoteQuery("CALL InsertNewUser('John', 'Smith', 'jsmith@hotmail.com', '3014337474')", NEW_USER)
and I have this in the JobDone sub
B4X:
Dim res As String
res = Job.GetString
      
Dim parser As JSONParser
parser.Initialize(res)

SPResult = parser.NextArray 'returns a list with maps
Dim m As Map
m = SPResult.Get(0)
msgbox(m.Get("Result")
Everything is working fine, but like you say, I don't think that this is a map, so, what should be the right way to get a single value ?

thanks
 

DonManfred

Expert
Licensed User
Everything is working fine, but like you say, I don't think that this is a map, so, what should be the right way to get a single value ?
fixing you php... i can not see any mysqlquery call before the line
B4X:
while($r = mysql_fetch_assoc($sth)) {$rows[] = $r;
 
Top