Android Question Connecting MySql error OkHttpUtils2 / HttpUtils2. Help

studio4

Member
Licensed User
Longtime User
Hi,
I used B4A five years ago and now I would like work again with it, but somethings are changed.
I am trying to connect to a Mysql database (very simple). In the past, I used the http library and all works fine, but now It is impossible for me using the new library okhttputils, and okhttp library.
I read several post such as... https://www.b4x.com/android/forum/threads/httputils2-web-services-are-now-even-simpler.18992/ but I can not understand it.

I have attached a screenshot about the error and the code. Help me please.
Sorry. My english skill is very low.
 

Attachments

  • error.png
    20 KB · Views: 141
  • sample.zip
    8.5 KB · Views: 125

walterf25

Expert
Licensed User
Longtime User
I would suggest checking your php file, make sure the php file is in the folder or directory that you are pointing to in your code, or that it doesn't contain any errors, also check and make sure you have the right credentials, username, password etc.

The error you are getting is very obvious, you are expecting a Json Array, but instead you are receiving a String.

You should check out this tutorial instead.

Walter
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
you are expecting a Json Array, but instead you are receiving a String.
the result is the content from this url: https://hosting.miarroba.com/indice.php
The call is redirected to this url. Account deleted/deactivated?

 
Last edited:
Upvote 0

studio4

Member
Licensed User
Longtime User
Free accounts usually get deleted after a while of not using it.

It this the case maybe? Check their website if you still can login to your account.

I have checked it and I can login without problems, but certanly I think that the problem may be due to the advertisements of the website.
 
Upvote 0

studio4

Member
Licensed User
Longtime User
Hello again,

Finally, I have decided to by a hosting and a domain (not free) to avoid possible errors, but my app doesn’t work again.

Certainly, the error has changed, but I can not to resolve it.

I have changed all the parameters in the app and .php file. Attachment it. Please help.

This is my .php file:

<?php

$databasehost = "localhost";
$databasename = "test1";
$databaseusername ="user1";
$databasepassword = "pwduser1";

$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);
?>
 

Attachments

  • error.png
    22.7 KB · Views: 109
  • test.zip
    8.6 KB · Views: 125
Upvote 0

studio4

Member
Licensed User
Longtime User
Thank you for your help.
I have resolved the problem. It consisted of an incorrect setting of my hosting server. I asked to the admin of it and now, it is all is ok.
Thank you again.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…