Android Question Connect to MySQL Database sending configuration

Ariston

Member
Licensed User
Longtime User
Hi!

I am using webservice.php, explained here, to make CRUDs in MySQL via http sucessfully. But I would like to know if there is a way to send database name, user name and password.
In the examples I found, these information are already in the webservice.php but I would like to send them as a parameter of the url.

Is it possible?

This is how I am using:

My BRA code:
        Dim QryItn As String
        QryItn = "INSERT INTO app_peditens (PEDIDO, CODITM, GTIN, DESCRI, TABELA, QUANTI, PRUNIT, PTOTAL, IMPORTID) VALUES " & CRLF & lstItn
        Dim Job2 As HttpJob ' For examples, see: https://www.b4x.com/android/forum/threads/b4x-okhttputils2-with-wait-for.79345/
        Job2.Initialize("Job2", Me)
        Job2.PostBytes("http://www." & cUrl.Trim & "/webervice.php", QryItn.GetBytes("UTF8"))
        Wait For (Job2) JobDone(Job2 As HttpJob)
        Job2.Release

My php page:
<?php
   $databasehost = "localhost"; // This a want to get from url parameter
   $databasename = "kazam_bd"; // This a want to get from url parameter
   $databaseusername ="username"; // This a want to get from url parameter
   $databasepassword = "password"; // This a want to get from url parameter

   $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 "Error: " . 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);
?>

Thanks in advance.
 

DonManfred

Expert
Licensed User
Longtime User
I am using webservice.php, explained here,
You DID read the very 1st sentence?

A new more powerful framework is now available: jRDC2.

Fazit: you should use jRDC2

Out from security you should NEVER NEVER NEVER put your DB-Credentials in your app.

Instead you should have them in the php-Script if you want to use PHP. the suggested method is to use jRDC2.
 
Last edited:
Upvote 0
Top