Android Tutorial Connect Android to MySQL Database Tutorial

Status
Not open for further replies.

Erel

B4X founder
Staff member
Licensed User
Longtime User
i can do that with basic4android?.
Yes.

This PHP script however doesn't support blobs. You will need to modify it. The simplest solution will be to encode the data as base64 string and then decode it in the PHP script and add it to the database (if you can store the data encoded in base64 then you do not need to change the script at all).
 

giannimaione

Well-Known Member
Licensed User
Longtime User
connect mysql remote with B4PPC ?

Hi Erel,

i forgot, :BangHead:
there is a way to connect with B4PPC to remote DB mysql ?
thanks
 

oscar cabrales

Member
Licensed User
Longtime User
thanks!!!



thanks EREl my program now load and download images to and from mysql
greetings from colombia
:sign0098:
 

shashkiranr

Active Member
Licensed User
Longtime User
Hi ,

I am using xampp and installed mysql. I copied the php code from the first post and corrected the first line. My php script is

<?php

$databasehost = "localhost";
$databasename = "test_b4a";
$databaseusername ="test";
$databasepassword = "test";

$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
$query = file_get_contents("php://input");
$sth = mysql_query($query);

if (mysql_errno()) {
header("HTTP/1.1 500 Internal Server Error");
echo $query.'\n';
echo mysql_error();
}
else
{
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
}
?>

I gave the link in the app as
req.InitializePost2("http://localhost/countries.php", Query.GetBytes("UTF8"))

I got this error Error: org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused, StatusCode: -1 . I saw few previous posts where ppl encountered this but no one has specified how they solved it

Anyone can tell me how to connect to local host Database.

One more question The database test_b4a has the table testcountries in which all the countries info are stored. is the $databasename = "test_b4a" correct or $databasename = "testcountries" is correct??
 

shashkiranr

Active Member
Licensed User
Longtime User
Erel i have installed Xampp in my laptop , I used 10.0.0.2 and changed $databasehost = "10.0.0.2"; and i got this error

Error: java.net.SocketTimeoutException: Socket is not connected, StatusCode: -1

I also used 127.0.0.1 which is local host address but still got the same error as the one posted in my previous post...

im using wifi bridge and testing on my phone
 

mc73

Well-Known Member
Licensed User
Longtime User


I see. Great!
 

Noel

Member
Licensed User
Longtime User

Hello Erel,

How should the code look like when using the 1st (way more secure) option? (me hate mySQL injection) :-/
 

ivanomonti

Expert
Licensed User
Longtime User
mmm error:

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in /mc.php on line 8
Lost connection to MySQL server at 'reading initial communication packet', system error: 111

$query = file_get_contents("php://input"); ???

how can I fix, Thank
 

ivanomonti

Expert
Licensed User
Longtime User

resolved, do not want to host name but ip, Thank
 
Last edited:

Sinan Tuzcu

Well-Known Member
Licensed User
Longtime User

Hallo Erel,

where exactly the line should be?
B4X:
SELECT CONVERT(Column1 USING utf8) FROM ...

can you please show me how I install your example, here in the query?


I need to convert the column Nachrichten
B4X:
ExecuteRemoteQuery("SELECT Vorname, Name, Nachricht, Link FROM mesajlar  WHERE Vorname="Hans", "Name")

greet
sinan
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…