Ola
NB: The code here explains the use of parameter based queries for CRUD
I have been exploring MySQL with BANano, this was previously done using external PHP files and thus using .CallAjax BANano Calls.
This was explained in
[BANano] MySQL CRUD with PHP - Part 1
[BANano] MySQL CRUD with PHP - Part 2
The final thread on this topic is BANanoMySQL
Part 3.1 is a beginning of an exercise to reach CRUD functionality, as an intro to how I'm currently managing a little bit of database administration using inline php, thanks to BANano.
I guess after exploring more of inline php with my other thread here, I have like fallen inlove at how simple it is. Off course, not being an expert on PHP is rather posing a challenge. I've spent a lot of time just researching, debugging, curly brackets are a pain yho!
This is what we will do here...
1. Test a connection to MySQL
2. Create a database in MySQL
3. Drop the MySQL database
4. Create a table in the MySQL server
5. Drop the table in the MySQL database
6. Drop the database
How is this done?
A class module to build generic SQL commands exists, this is used to build any SQL queries that we need to pass to out inline PHP, specifically for CRUD functionality. The existence of a single PHP script to handle all the commands for CRUD ensures that any CRUD specific project can easily use the PHP script and the class module to perform such functions. The dependency will just be the data and nothing else.
This is all done with inline php and just calling a single function from it, MySQL_ExecuteOnly Wow! Here is it.
Assumptions:
Let's start
I am creating a mocking app which has to create a backend MySQL db, create the needed table, generate dummy data as a start. How to generate dummy data using and extending an existing code module was discussed on my post here.
On AppStart, we need to tell BANano the details of the PHP file we are using...
The contents of the PHP file on your build folder, will not be generated until you call CallInlinePHP - kinda cool.
Designing UOEMock - An internal app for the TGIF Zone Inc.
The app I'm working on features a treeview and a grid. I did a discussion about the treeview here and the grid has been featured here. I had created a UX lib that I'm using for my BANano apps, this was also featured here.
How the EasyHints class was used for the hints was also featured here.
Let's watch something...
NB: The code here explains the use of parameter based queries for CRUD
I have been exploring MySQL with BANano, this was previously done using external PHP files and thus using .CallAjax BANano Calls.
This was explained in
[BANano] MySQL CRUD with PHP - Part 1
[BANano] MySQL CRUD with PHP - Part 2
The final thread on this topic is BANanoMySQL
Part 3.1 is a beginning of an exercise to reach CRUD functionality, as an intro to how I'm currently managing a little bit of database administration using inline php, thanks to BANano.
I guess after exploring more of inline php with my other thread here, I have like fallen inlove at how simple it is. Off course, not being an expert on PHP is rather posing a challenge. I've spent a lot of time just researching, debugging, curly brackets are a pain yho!
This is what we will do here...
1. Test a connection to MySQL
2. Create a database in MySQL
3. Drop the MySQL database
4. Create a table in the MySQL server
5. Drop the table in the MySQL database
6. Drop the database
How is this done?
A class module to build generic SQL commands exists, this is used to build any SQL queries that we need to pass to out inline PHP, specifically for CRUD functionality. The existence of a single PHP script to handle all the commands for CRUD ensures that any CRUD specific project can easily use the PHP script and the class module to perform such functions. The dependency will just be the data and nothing else.
This is all done with inline php and just calling a single function from it, MySQL_ExecuteOnly Wow! Here is it.
B4X:
#if PHP
function MySQL_ExecuteOnly($servername,$username,$password,$db,$sql,$command) {
//set the header
header('content-type: application/json; charset=utf-8');
//connect to MySQL
$conn = new mysqli($servername, $username, $password);
//we cannot connect return an error
if ($conn->connect_error) {
$response = $conn->connect_error;
$output = json_encode(array("response" => $response));
die($soutput);
}
if ($command == "connection"){
// we were just testing the connection
$response = "OK";
} else {
//if we are creating/dropping the db, just execute sql
$someCommands = array('createdb', 'dropdb');
$sql = mysqli_real_escape_string($conn, $sql);
$db = mysqli_real_escape_string($conn, $db);
if(in_array($command,$someCommands)) {
if ($conn->query($sql) === TRUE) {
$response = "OK";
} else {
$response = $conn->error;
}
} else {
//select db and execute sql if db exist
$selected = mysqli_select_db($conn,$db);
if (!$selected) {
$response = $conn->error;
$output = json_encode(array("response" => $response));
die($output);
}
if ($conn->query($sql) === TRUE) {
$response = "OK";
} else {
$response = $conn->error;
}
}
}
$output = json_encode(array("response" => $response));
echo($output);
$conn->close();
}
#End If
Assumptions:
- I am testing this with XAMP with MySQL installed.
- I will assume that you can create UX with BANano as only the logic of the code will be discussed here. This includes using .GetValue, .SetValue, .GetChecked, .SetChecked.
- The focus here is rather on using the inline php.
Let's start
I am creating a mocking app which has to create a backend MySQL db, create the needed table, generate dummy data as a start. How to generate dummy data using and extending an existing code module was discussed on my post here.
On AppStart, we need to tell BANano the details of the PHP file we are using...
B4X:
BANano.PHP_NAME = "uoemock.php"
BANano.PHPHost = "http://localhost/" & ShortName & "/"
BANano.PHPAddHeader("Access-Control-Allow-Origin: *")
The contents of the PHP file on your build folder, will not be generated until you call CallInlinePHP - kinda cool.
Designing UOEMock - An internal app for the TGIF Zone Inc.
The app I'm working on features a treeview and a grid. I did a discussion about the treeview here and the grid has been featured here. I had created a UX lib that I'm using for my BANano apps, this was also featured here.
How the EasyHints class was used for the hints was also featured here.
Let's watch something...
Attachments
Last edited: