Android Question Connect Android to remote MySQL Database : Problem when migrating to a new server

Che Mohamad

Member
Licensed User
Dears (Hi Erel),
I have been using, for more than 2 years the Tutorial by Erel here to connect my apps to remote mysql server, without any issues.
The below PHP code "
B4X:
<?php

$databasehost = "localhost";
$databasename = "xxxx";
$databaseusername ="xxxx";
$databasepassword = "xxxx";

$con = mysqli_connect($databasehost,$databaseusername,$databasepassword, $databasename) or die(mysqli_error($con));
mysqli_set_charset ($con , "utf8");
$query = file_get_contents("php://input");
$sth = mysqli_query($con, $query);

if (mysqli_errno($con)) {
   header("HTTP/1.1 500 Internal Server Error");
   echo $query.'\n';
   echo mysqli_error($con);
}
else
{
   $rows = array();
   while($r = mysqli_fetch_assoc($sth)) {
     $rows[] = $r;
   }
   $res = json_encode($rows);
    echo $res;
    mysqli_free_result($sth);
}
mysqli_close($con);
?>

However I have decided to migrate the server to a new remote server (website hosting) :
1. No issue when posting "SELECT" statement
2. Issue when posting "INSERT" or "UPDATE" statement. The "JobDone(Job As HttpJob)" will return Job.ErrorMessage as "" (no string message).
After INSERT or UPDATE statement, I checked that the record has been inserted or updated in mySQL server, however the return message is the issue here.
This issue didn't occurs while using the old server. In the old server it will return as Job.Success = True

Is there something at the server setting that I need to change of the PHP code itself?
In Erel's tutorial he mentioned that "I've restricted the database user to SELECT queries (in MySQL configuration)"
Could it be the reason? If so where exactly do I need to change?

Thank you for your feedback.
 

josejad

Expert
Licensed User
Longtime User
Could it be the reason? If so where exactly do I need to change?
Yes, that could be the problem. Check your database with phpMyAdmin or any other DBMS to check if the user you're using to connect to your database has permissions to write on db.
 
Upvote 0

Che Mohamad

Member
Licensed User
Yes, that could be the problem. Check your database with phpMyAdmin or any other DBMS to check if the user you're using to connect to your database has permissions to write on db.
Additional info : after INSERT or UPDATE statement, I checked that the record has been inserted or updated in mySQL server, however the return message is the issue here.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I have been very long time no program with PHP but I think you are doing something wrong in your PHP.

SELECT query -> returns results.
INSERT / UPDATE -> does NOT return results.

When you use mysqli_fetch_assoc(), it should return the array of data when you do a SELECT query. This has nothing to do with INSERT/UPDATE queries.
 
Upvote 0
Top