Android Question b4a and php codes not working after upgrading to b4a version 8.0

Gbenga Odumosu

Member
Licensed User
Longtime User
View attachment 70972 View attachment 70972 I have a project that retrieve information from database through php codes , but after upgrading to 8.0 b4a i started getting lots off errors or returning null as result or giving java.lang.RuntimeException: JSON array expected. i have done all i could without solution. is their anything i am not doing? help pls . I used example example giving by Kmatle in his tutorial

my php code is

<?

#include ("db.php");
#$host = "localhost";
#$user = "y";
#$pw = "a";
#$db = "tolu";

#$con = mysql_connect($host,$user,$pw) or die(mysql_error());

$con = mysqli_connect("localhost", "y", "a", "tolu");



// Check connection

if($con === false){

die("ERROR: Could not connect. " . mysqli_connect_error());

}

mysqli_query("SET CHARACTER SET utf8");

$action = $_GET["action"];

switch ($action)

{
case "CountPersons":
# print json_encode("just yap");
$q = mysql_query("SELECT * FROM persons");
$count = mysql_num_rows($q);
print json_encode($count);
break;

Case "GetPersons":
$q = mysql_query("SELECT name, age FROM Persons");
$rows = array();
while($r = mysqli_fetch_assoc($q))
{
$rows[] = $r;
}
print json_encode($rows);
break;

case "InsertNewPerson":
$name = $_GET["name"];
$age = $_GET["age"];
$q = mysqli_query("INSERT INTO Persons (name, age) VALUES ('$name', $age)");
print json_encode("Inserted");
break;

}





?>
 

Attachments

  • b4php.zip
    8.5 KB · Views: 275

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Nothing has changed in B4A v8 that can affect your http requests.
2. You should never use Msgbox to monitor the program state. Use Log instead.
3. HttpJob can be simplified: [B4X] OkHttpUtils2 with Wait For
4. You already posted this question here: https://www.b4x.com/android/forum/t...ing-after-upgrading-to-b4a-version-8-0.96029/
You were given all kinds of suggestions. You should post the updated code.
5. We cannot help you without seeing the logs.
6. Why are you using PHP if you are not familiar with PHP? It will be simpler to use B4J and build a more robust backend.
7. If you want to access a remote database then use jRDC2.
 
Upvote 0

Gbenga Odumosu

Member
Licensed User
Longtime User
1. Nothing has changed in B4A v8 that can affect your http requests.
2. You should never use Msgbox to monitor the program state. Use Log instead.
3. HttpJob can be simplified: [B4X] OkHttpUtils2 with Wait For
4. You already posted this question here: https://www.b4x.com/android/forum/t...ing-after-upgrading-to-b4a-version-8-0.96029/
You were given all kinds of suggestions. You should post the updated code.
5. We cannot help you without seeing the logs.
6. Why are you using PHP if you are not familiar with PHP? It will be simpler to use B4J and build a more robust backend.
7. If you want to access a remote database then use jRDC2.


Cant we have a step by step tutorial on issues rather than going from one idea to other, do i need to buy B4J and abandon b4a or what . you guys thinks easily that everybody should understand things easily. This is a new area i am trying to get to . can i have support on step by step on what to do if i want to get WHAT? the video tutorial is too general for newbie like us. or a sample that works.

thanks anyway
 
Upvote 0

asales

Expert
Licensed User
Longtime User
do i need to buy B4J and abandon b4a or what
Why the negative attitude?
Do you know what is the difference between B4A and B4J (which is free)?

You have the step by step here:
https://www.b4x.com/android/forum/t...-local-php-mysql-server-xampp-with-b4a.48635/

I don't know PHP (and this forum is not to PHP), but I checked your PHP code (and the code from @KMatle) and you changed all the PHP code. So, you need to know what do you doing in PHP.

the video tutorial is too general for newbie like us.
And if you is a newbie, is best to start with general information and grow up. The videos from Erel are great.

can i have support on step by step on what to do if i want to get WHAT?
I think it's better to teach you to fish than to give you a fish.
 
Last edited:
Upvote 0

Dabzy1978

Member
Licensed User
I'm working on a B4A app that sends messages to a server, which is handled by PHP and returns messages back, it all works!

Now the problem with PHP is that its syntax is bloody god awful, but that's offset in the sense that it works really well.

My advice would be to use that LAMP on your computer, and build yourself a simple little browser based web service with PHP, nothing major, maybe a little phone directory where you can add/remove/view items, something like that.

Bonus is, you'll get a handle on mySQL as well, which is good to know, and will become invaluable for storing/using your data in a meaningful way.

the video tutorial is too general for newbie like us.

Everyone was a newbie once, I think programmers appreciate that fact, and we are all learning all the time... Difference is though, most newbies roll up their sleeves and dont expect miracles from the offset, start small and work up... Read/code/learn rinse repeat

You really need to tinker with things first, before you try and combine technologies like this into one package... Rome wasnt built in a day!

Dabz
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
do i need to buy B4J and abandon b4a or what
It is clear that you don't want to do the minimum work required for learning. B4J is a free tool for desktop and server solutions.
https://www.b4x.com/b4j.html
Communicating with a remote server is not a trivial task. There are many options and things to consider.

As I already told you, if you want to access a remote database then use jRDC2.
 
Upvote 0
Top