Hi there
Update: 2019-12-17 BANanoMySQL class updated, see post #11, https://www.b4x.com/android/forum/t...mysqli-crud-functionality.106858/#post-700010
Update: BANanoMySQL1 Example
If you would rather use an actual sqlite db, you can use BANanoSQLite.
NB: This uses parameter based queries and these expect S,I,D,B (String,Integer,Double,Blob) field definitions in the queries.
IMPORTANT NOTICE: UPDATED CODE ON POST #7
I have been exploring MySQL Php for a while now for BANano and I am glad to have finally finished a simple class that anyone can use for CRUD functionality. The basis for this has been DBUtils.
If you recall, I explored this in post about inline php for MySQL here.
To explain this functionality, we are continuing with the tabbed dialog to login, reset password, change password, register and forgot password as explained here.
So this post is the consolidation of those 2 sessions and then with some tweaking, having a simple class to use.
I am using this successfully for my projects in Things Created with BANano
To demonstrate, the CRUD functionality we will do the following:
1. Register - INSERT (insert)
2. Login - READ (selectwhere)
3. Forgot Password - READ (selectwhere)
4. Reset Password - READ + UPDATE (selectwhere + updatewhere)
5. Change Password - READ + UPDATE (selectwhere + updatewhere)
6. De-Active Profile - DELETE (deletewhere)
So how does the BANanoMySQL class work?
The class itself helps one to generate sql queries that are later passed to CallInlinePhp(Wait). I have grown to like the ones with Wait because it makes reading the code much better.
The BANanoMySQL class is used mainly to build up the JSON content that the BANanoMySQL php function receives to be able to run and return a result. The generated JSON result, whether for a SELECT, INSERT, DELETE, UPDATE etc, is returned in this format.
The sql - this is the actual sql command to execute, e.g. INSERT INTO .... this will include the ? marks for your arguements.
The args - this is a list of the arguements to process in the parameter query.
The types - this is a list of the data types for the fields being parameterized. ONLY s-tring,i-integer,d-ouble and b-blob is acceptable here i.e sidb.
This should be in the sequence of the parameters and the BANanoMySQL class will build these for you.
By default all fields are assumed to be strings for this. You need to specifically indicate that particular fields are integers, doubles, blobs. Integer just relates to anything numeric and not a double.
The command - this is the command to be executed. These are 'select', 'deletewhere', 'updatewhere', 'selectwhere' and 'insert' . Any other commands are executed and a result of 'OK' or the mysql error response. These commands are generated by BANanoMySQL class depending on the operation you need to execute for the various methods.
BANanoMySQL Response
The response for the BANanoMySQL php is always a JSON string with the following keys 'response' and 'data'. When things are ok, the response will always be 'OK' and the 'data' will return the contents of the sql command response, whether affectedrecords / actual list of records.
Obvious Assumptions: You have a UX defined for your app and need inline php MySQL database functionality. This means that I will not be dwelling much on the UX here but just the functionality for CRUD for inline php. I am using my own developed UOENow library for this and will make the 'free' components version available soon. The professional version of Creative Tim's Now UI Kit Pro is not distributable for these kinds of things.
Update: 2019-12-17 BANanoMySQL class updated, see post #11, https://www.b4x.com/android/forum/t...mysqli-crud-functionality.106858/#post-700010
Update: BANanoMySQL1 Example
If you would rather use an actual sqlite db, you can use BANanoSQLite.
NB: This uses parameter based queries and these expect S,I,D,B (String,Integer,Double,Blob) field definitions in the queries.
IMPORTANT NOTICE: UPDATED CODE ON POST #7
I have been exploring MySQL Php for a while now for BANano and I am glad to have finally finished a simple class that anyone can use for CRUD functionality. The basis for this has been DBUtils.
If you recall, I explored this in post about inline php for MySQL here.
To explain this functionality, we are continuing with the tabbed dialog to login, reset password, change password, register and forgot password as explained here.
So this post is the consolidation of those 2 sessions and then with some tweaking, having a simple class to use.
I am using this successfully for my projects in Things Created with BANano
To demonstrate, the CRUD functionality we will do the following:
1. Register - INSERT (insert)
2. Login - READ (selectwhere)
3. Forgot Password - READ (selectwhere)
4. Reset Password - READ + UPDATE (selectwhere + updatewhere)
5. Change Password - READ + UPDATE (selectwhere + updatewhere)
6. De-Active Profile - DELETE (deletewhere)
So how does the BANanoMySQL class work?
The class itself helps one to generate sql queries that are later passed to CallInlinePhp(Wait). I have grown to like the ones with Wait because it makes reading the code much better.
The BANanoMySQL class is used mainly to build up the JSON content that the BANanoMySQL php function receives to be able to run and return a result. The generated JSON result, whether for a SELECT, INSERT, DELETE, UPDATE etc, is returned in this format.
B4X:
Dim m As Map
m.Initialize
m.Put("sql", SQL)
m.Put("args", Null)
m.Put("types", Null)
m.Put("command", "createdb")
Dim res As String = Map2Json(m)
The sql - this is the actual sql command to execute, e.g. INSERT INTO .... this will include the ? marks for your arguements.
The args - this is a list of the arguements to process in the parameter query.
The types - this is a list of the data types for the fields being parameterized. ONLY s-tring,i-integer,d-ouble and b-blob is acceptable here i.e sidb.
This should be in the sequence of the parameters and the BANanoMySQL class will build these for you.
By default all fields are assumed to be strings for this. You need to specifically indicate that particular fields are integers, doubles, blobs. Integer just relates to anything numeric and not a double.
The command - this is the command to be executed. These are 'select', 'deletewhere', 'updatewhere', 'selectwhere' and 'insert' . Any other commands are executed and a result of 'OK' or the mysql error response. These commands are generated by BANanoMySQL class depending on the operation you need to execute for the various methods.
BANanoMySQL Response
The response for the BANanoMySQL php is always a JSON string with the following keys 'response' and 'data'. When things are ok, the response will always be 'OK' and the 'data' will return the contents of the sql command response, whether affectedrecords / actual list of records.
Obvious Assumptions: You have a UX defined for your app and need inline php MySQL database functionality. This means that I will not be dwelling much on the UX here but just the functionality for CRUD for inline php. I am using my own developed UOENow library for this and will make the 'free' components version available soon. The professional version of Creative Tim's Now UI Kit Pro is not distributable for these kinds of things.
Attachments
Last edited: