Before you start: You need some experience with php, Apache Servers, OkHttpUtils, Lists, Maps and JSON structures.
This is an updated example of how to
- communicate with a apache server via OKHttpUtils calling a php script
- doing MySQL data requests (Insert, Update and Delete) using prepared sql statements
- working with the data like list's & maps (= arrays in php) in both direction (I use this contellation combined with encryption and Base64 a lot in my apps)
- using resumable subs with parameters
It's a simple example It doesn't check any server responses (you can add that of course as the script is returning structured responses as a list)
What you need;
A running Apache/PHP environment
Test: I use XAMPP: https://www.apachefriends.org/de/index.html Just install the package and start the Apache and MySQL process. Don't forget to enable the firewall otherwise your app will be blocked.
Prod: Same thing (almost). I use a cheap hosted server which has MySQL and PHP. Just change the script. Please note that this is a BASIC script to show how it works. You need to add much more security. Don't just run that script in production! Don't think "maybe"
MySQL
I've added a *.sql script. Just run it in the MySQL-admin UI of your php installation. It creates the database and the needed table.
PHP
The script is included, too. Just copy the folder to Apache's htdocs folder.
IP address
Inside the B4J app: Set it to the pc's ip address where your apache & MySQL is running. Can be on the same machine as your B4J-app is running.
PHP: It's localhost (because the Apache is running on the same machine as MySQL here). In production your provider will have all paramaters for you.
Can I use the code in B4A?
Yep. Just copy the code. Adapt it slightly (e.g. use a service for the server calls).
More infos
PHP/MySQL: https://www.w3schools.com/php/php_mysql_prepared_statements.asp
This is an updated example of how to
- communicate with a apache server via OKHttpUtils calling a php script
- doing MySQL data requests (Insert, Update and Delete) using prepared sql statements
- working with the data like list's & maps (= arrays in php) in both direction (I use this contellation combined with encryption and Base64 a lot in my apps)
- using resumable subs with parameters
It's a simple example It doesn't check any server responses (you can add that of course as the script is returning structured responses as a list)
What you need;
A running Apache/PHP environment
Test: I use XAMPP: https://www.apachefriends.org/de/index.html Just install the package and start the Apache and MySQL process. Don't forget to enable the firewall otherwise your app will be blocked.
Prod: Same thing (almost). I use a cheap hosted server which has MySQL and PHP. Just change the script. Please note that this is a BASIC script to show how it works. You need to add much more security. Don't just run that script in production! Don't think "maybe"
MySQL
I've added a *.sql script. Just run it in the MySQL-admin UI of your php installation. It creates the database and the needed table.
PHP
The script is included, too. Just copy the folder to Apache's htdocs folder.
IP address
Inside the B4J app: Set it to the pc's ip address where your apache & MySQL is running. Can be on the same machine as your B4J-app is running.
PHP: It's localhost (because the Apache is running on the same machine as MySQL here). In production your provider will have all paramaters for you.
Can I use the code in B4A?
Yep. Just copy the code. Adapt it slightly (e.g. use a service for the server calls).
More infos
PHP/MySQL: https://www.w3schools.com/php/php_mysql_prepared_statements.asp