Android Question Connecting to mysql database in a computer localhost

khwarizmi

Active Member
Licensed User
Longtime User
Hi all
How to connect to mysql database in a computer localhost from another device. both of them in the same net work. I tried to access through the IPv4 Address: 192.168.8.4. But I got access denied.
B4X:
Dim job2 As HttpJob
    job2.Initialize("", Me)
    job2.download("http://192.168.8.4/shops/shopexists.php?dv=" & d)
    ProgressDialogShow("Loding..")
    Wait For (job2) JobDone(job2 As HttpJob)
    ProgressDialogHide
    Dim res As String
    res = job2.GetString
    Log(res)

the error I got is:
java.io.FileNotFoundException: /data/user/0/com.ggt.janadmin/cache/1: open failed: ENOENT (No such file or directory)

It seems as if it is trying to read from the mobile itself
 
Last edited:

mc73

Well-Known Member
Licensed User
Longtime User
After ProgressDialogHide, use
B4X:
if job2.success then 
dim res as string=job2.getstring
log(res)
else
log(j2.errorMessage)
end if 
job2.release
This way, you'll get the "real" error, which in your case might be due to your pc firewall.
 
Upvote 0

khwarizmi

Active Member
Licensed User
Longtime User
thanks @mc73 , @José J. Aguilar :
This way, you'll get the "real" error, which in your case might be due to your pc firewall.
the error message now is:
org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.8.4 refused

Try to access from the android or other computer in the network from a browser to:
http://192.168.8.4/shops/shopexists.php?dv=1 It's easier to test from a browser than your app.
I got access denied
when I turned on firewall the message was:
this site can't be reached.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Hi Kattah,
When you setup a connection to a 192.168.8.4 address without telling which port you want to use, the system will take port 80 (plane HTTP) or 443 (encrypted HTTPS). The default MySQL port is 3306 for the CDBR endpoint. If you want to connect to the database master, you must uses the port 3310 So I think that you should setup the connection to 192.168.8.4:3306.
Be aware that most Operating Systems blocks incoming traffic.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
If you are on the computer that has this, how are you accessing this via the browser? What is the url?
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
The
If you are on the computer that has this, how are you accessing this via the browser? What is the url?
I cannot see what the value is of the variable 'd'. We solve that challenge as follow, by adding the following code between line 3 and 4 in yours first code block.

Add the following code (don't forget to add the ':3306' port definition for CDBR or ':3310' for administration access or use any other configured portnummer of the MySQL server):
B4X:
log("http://192.168.8.4:3306/shops/shopexists.php?dv=" & d)
1) Copy the result in the log to the clipboard
2) Open the browser
3) Replace the url with a paste from the clipboard
4) Hit Enter

Wait for any reaction on hitting some key. Perhaps you see a username or password request text or garbage. Anyway, any response is a sign of connectivity.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
The

I cannot see what the value is of the variable 'd'. We solve that challenge as follow, by adding the following code between line 3 and 4 in yours first code block.

Add the following code (don't forget to add the ':3306' port definition for CDBR or ':3310' for administration access or use any other configured portnummer of the MySQL server):
B4X:
log("http://192.168.8.4:3306/shops/shopexists.php?dv=" & d)
1) Copy the result in the log to the clipboard
2) Open the browser
3) Replace the url with a paste from the clipboard
4) Hit Enter

Wait for any reaction on hitting some key. Perhaps you see a username or password request text or garbage. Anyway, any response is a sign of connectivity.
I forgot to say that if you don't get any response you can replace the external interface address 192.168.8.4 by the internal loopback address 127.0.0.1 to perhaps bypass the firewall restrictions if you can start a web browser on the same MySQL server. Take time to see what happing because sometimes the server drops the logon session with some kind of a logout message.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

MicroDrie

Well-Known Member
Licensed User
it should not be port 3306, that's MySQL direct. Poster is using a PHP script to access the data.

Yes, poster needs to get on the computer that hosts the PHP script and use a browser to get to the information. Once successful, the URL that was used to access the information needs to be posted here.
Sorry my mistake it it must be:
B4X:
log("http://192.168.8.4/shops/shopexists.php?dv=" & d)
log("http://192.168.8.4:80/shops/shopexists.php?dv=" & d)
log("http://192.168.8.4:443/shops/shopexists.php?dv=" & d)
In that case it is interesting to know what the response is, because it could be that an other service is running on port 80 / 443. Therefore José J. Aguilar was advice to use xampp which can inform which services are active on which port.
 
Upvote 0

khwarizmi

Active Member
Licensed User
Longtime User
Thank you for all your assistance @MicroDrie , @OliverA .

I tried the address in the computer browser, and it is working fine.
The problem was with Wampserver (it might need some settings)
Now I'm using xampp , and it working well!
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Kattah it is always nice to read that we all managed to successfully complete a challenge.
 
Upvote 0
Top