Android Question Put data to MySQL Database?

ilan

Expert
Licensed User
Longtime User
Hi

until today i have sending data to my mySQL DB via php. I have a shared hosting and some mysql db on it. is there a different way to send data to mysql?

it seems like when i send it via php it is not updated immidiatley. sometimes i take some minutes until i see the updated data. is it normal like this? can it be that it has something to do with okhttp?

thanx, ilan
ps.: my hosting is on WHOIS.COM. if you know a better company please let me know i am ready to pay more for my hosting if it runs faster and better. thanx
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

aeric

Expert
Licensed User
Longtime User
You may refer to my code snippet Register User example using HttpUtils2

Version 1.3 (Update 08 Feb 2019)
- Set targetSdkVersion=26
- Replaced HttpUtils2 with OKHttpUtils2
- Changed conflicting Job names with module names
- Added Change Password activity
- Removed Forgot Password activity
- Replaced MySQL functions in PHP script with MySQLi functions
- Added db.php in PHP script to store global variables
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Upvote 0

ilan

Expert
Licensed User
Longtime User

hi again, i just had a look at it. and the prices are very good. so if i purchase a package on this hosting i can use jrdc?
so how does it works exactly? i uploade the server.jar that is created with b4j to my ftp account and then i can connect my b4a app and send data to that server and receive data from it?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

aeric

Expert
Licensed User
Longtime User
i also shared an example using php + mysql. but i dont understand what you mean change mysql to mysqli

Here is your code (modified)
PHP:
<?
$table = "tbl_users";
include ("db.php");

// $con = mysql_connect($host, $user, $pw) or die(mysql_error());
// mysql_select_db($db) or die(mysql_error());
// mysql_query("SET CHARACTER SET utf8");
// mysql_query("SET NAMES 'utf8'");

$con = new mysqli($host, $user, $pw, $db);
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
mysqli_set_charset($con, "utf8");

$action = $_GET["action"];
 
switch ($action)
{
    Case "GetUserName":
        $username = $_GET["username"];
        // $q = mysql_query("SELECT password FROM $table WHERE username='$username'");
        $q = mysqli_query($con, "SELECT password FROM $table WHERE username='$username'");
        $rows = array();
        // while($r = mysql_fetch_assoc($q))
        while($r = mysqli_fetch_assoc($q))
        {
            $rows[] = $r;
        }
        print json_encode($rows);
    break;
  
    case "SignUp":
        $username = $_GET["username"];
        $password = $_GET["password"];
        // $q = mysql_query("INSERT INTO $table (username, password) VALUES ('$username', '$password')");
        $q = mysqli_query($con, "INSERT INTO $table (username, password) VALUES ('$username', '$password')");
        print "Inserted";
    break;
}
?>
where do i make the change? in the cpanel of my hosting?
If you get error mysqli not supported then you need to enable the module in PHP Selector in CPanel
upload_2019-4-4_18-22-9.png
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
so how does it works exactly? i uploade the server.jar that is created with b4j to my ftp account and then i can connect my b4a app and send data to that server and receive data from it?
as written: you need a VPS for jRDC2.

Cheap one i am using

https://www.strato.de/server/linux-vserver/

With a VPS you connect using ssh to send commands. For ex, start your jar file with jrdc2...
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
You can also use Amazon AWS services, as it is very good; It also has a free version for one year and that is enough for you to rehearse your projects using a JRDC2 server. If you need more information, you can write to me.
Regards!
Johan H
 
Upvote 0
Top