Android Question Mysql & Xampp. Connection Error

Daniel44

Active Member
Licensed User
Hi Everyone!

I'm testing on my lap with xampp this example :https://www.b4x.com/android/forum/threads/mysql-data-to-webview-using-php.104274/#content of Mashiane. I've modified the php file on the project with my local ip

B4X:
<?php
$servername = "localhost:84";
$dbname = "phplogin";
$username ="root";
etc..

it is port 84 because there is working my Xampp. I've changed several parameters, as "localhost" with 127.0.0.1 in the php file and also on the main module, I've also changed php file behind the project and php file in htdoc folder too but it can't connect
Anybody knows what or where is the mistake? Thank you so much

Log Error:
B4X:
ResponseError. Reason: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:84, Response:
B4X:
java.net.ConnectException: Failed to connect to localhost/127.0.0.1:84

Here are the project and my Xampp htdoc folder
 

Attachments

  • PHPLogin.zip
    216.5 KB · Views: 247
  • webandroid.zip
    1.1 KB · Views: 188
Last edited:

OliverA

Expert
Licensed User
Longtime User
The default port number for the database is 3306. Try that. If that does not work, google how to change the port on the database in xampp and you should find instructions on how to find the configuration file for the database.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
can your php page connect to the database?

the error you show mentions java so it's an output of the app.

first see if the php part is working before you move on to the app.

(if that works you probably only gave access to local host and the local host IP and not the rest of the subnet.) -> wrong info as server side always connects to the mysql from the same localhost/ip.
 
Last edited:
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
Point your web browser to 127.0.0.1:84/users.php

That will tell you if you PHP is connecting. You can build up a test string and just use it in the browser.

OliverA is correct. Need to change your port in the PHP file (or just remove it).

$servername = "localhost";

If the environment variable is set you can do it like:
$databasehost = $_ENV{'DATABASE_SERVER'};

If you plan on the app having a lot of users, you probably want to look at being able to store the passwords in encrypted form.
 
Upvote 0

Daniel44

Active Member
Licensed User
Yes
can your php page connect to the database?

the error you show mentions java so it's an output of the app.

first see if the php part is working before you move on to the app.

(if that works you probably only gave access to local host and the local host IP and not the rest of the subnet.) -> wrong info as server side always connects to the mysql from the same localhost/ip.
Yes. it works fine on my internet explorer (chtome) but not on the emulator thanks
 
Upvote 0

Daniel44

Active Member
Licensed User
I
Point your web browser to 127.0.0.1:84/users.php

That will tell you if you PHP is connecting. You can build up a test string and just use it in the browser.

OliverA is correct. Need to change your port in the PHP file (or just remove it).

$servername = "localhost";

If the environment variable is set you can do it like:
$databasehost = $_ENV{'DATABASE_SERVER'};

If you plan on the app having a lot of users, you probably want to look at being able to store the passwords in encrypted form.
I'll try that thank you so much
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
Yes. it works fine on my internet explorer (chtome) but not on the emulator thanks

that might depend on the emulators network settings being bridged or NAT. so it might be in its own subnet where it can't reach the subnet your server is in.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
so it might be in its own subnet where it can't reach the subnet your server is in
As sorex said, you should try to reach your webpage from the emulator explorer
 
Upvote 0

Daniel44

Active Member
Licensed User
T
that might depend on the emulators network settings being bridged or NAT. so it might be in its own subnet where it can't reach the subnet your server is in.
Thank you I'll try that. What would it be if I can't reach it from my emulator explorer? I was thinking set my router to a fixed ip and assign a non-dynamic ip to my emulator then turn off the dchp service.. would that be ok? Thank you
 
Upvote 0

Daniel44

Active Member
Licensed User
Point your web browser to 127.0.0.1:84/users.php

That will tell you if you PHP is connecting. You can build up a test string and just use it in the browser.

OliverA is correct. Need to change your port in the PHP file (or just remove it).

$servername = "localhost";

If the environment variable is set you can do it like:
$databasehost =
$_ENV{'DATABASE_SERVER'};
If you plan on the app having a lot of users, you probably want to look at being able to store the passwords in encrypted form.
Thank you you said $_ENV{'DATABASE_SERVER'}; is that another parameter? Thank you
 
Last edited:
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
Is this line correct?
Public IPAddress As String = "192.168.0.100:84" ' ip address of blue stacks

If you can connect to your server from Chrome on the device, then the problem is in your programming (not your network).
 
Upvote 0

Daniel44

Active Member
Licensed User
Cool
Is this line correct?
Public IPAddress As String = "192.168.0.100:84" ' ip address of blue stacks

If you can connect to your server from Chrome on the device, then the problem is in your programming (not your network).
Cool! I have to test this thank you so much
 
Upvote 0

Daniel44

Active Member
Licensed User
Inside my project under apache I've created a file called index.php with
B4X:
<?php

echo "Connected";


 ?>

I'm testing on my emulator internet navigator (Chrome). My emulator is my cell phone connected via bridge with the same subnet (192.168.0.) and I have tried to enter through the chrome of my emulator to the site this way : 192.168.0.100:84/webandroid/users.php... Also with localhost:84/webandroid/users.php and gives the error ERR_CONNECTION_REFUSED . I changed the port of my Xampp, in the httpd.conf file I told him to listen for the port 8080 and I entered with localhost:8080/webandroid/users.php also with 192.168.0.100:8080/webandroid/users.php and shows the same error.
 
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime User
it's all pretty vague...

does it work from another computer and not the one that has xamp running?

you wrote that you changed the listening port.

do you have

LISTEN 127.0.0.1:8080

there?

or just

LISTEN 8080

?

remove the ip or it won't work from anywhere exept the local machine that runs xamp
 
Upvote 0

Daniel44

Active Member
Licensed User
it's all pretty vague...

does it work from another computer and not the one that has xamp running?

you wrote that you changed the listening port.

do you have

LISTEN 127.0.0.1:8080

there?

or just

LISTEN 8080

?

remove the ip or it won't work from anywhere exept the local machine that runs xamp

Thanks for answering. In that conf file I just put Listen 8080. But it didn't work
 
Upvote 0

Daniel44

Active Member
Licensed User
I was finally able to enable it in my cell phone's internet browser this way:

In the Firewall in advanced configurations then in Rules of Entry I Allowed Connections to Apache HTTP Server Then I created a new rule for port 8080 (new entry->new rule-port) then at C:\xampp \apache\conf\extra modified the httpd-xampp file in line 105 (I opened it with notepad++) and commented the line that says : requires Local with a # remaining like this: # requires Local. Then you must restart the Xampp in order to work.

Now with this procedure I can see all my web projects on the cell phone from Xampp. I know this will help you many people.

But without being able to connect my app to my BD from my cell phone. Now I know that there is an error in the programming

of the app and not the connection.



Still Showing Error



ResponseError. Reason: java.net.SocketTimeoutException: timeout, Response:
java.net.SocketTimeoutException: timeout
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
well, first lesson is to disable your firewall and when everything works you enable it again and add the required ports.

did you change the port in your app source?
 
Upvote 0
Top