Which ip i should put on the url of my php request? - php

I am developing an application which basically starts with registration system using the wampserver to connect to mysql database through localhost/phpmyadmin as a back-end and android client using genymotion emulator as a front-end and both front and back end communicates through php/mysql API.
I have followed different tutorials to achieve all this but since none of them actually used genymotion I am missing the part of which IP, I should put for this mechanism to follow smoothly.

when you use emulator on you pc , your emulator will connect to virtual network interface that you can change it ....
you should check emulator network interface and enter your pc ip in that network interface ...
i attached a picture of setting of my emulator and you can see my emulator use my wifi network interface .... thus i should insert my computer ip address of wifi network interface
finally you should get your pc ip as network interface that your emulator connected to that and use that ip in emulator for connect to your webserver in your pc.....
in Wampserver, you can not access to apache from outside ...
you should change apache config (httpd.conf) and make access for outside connection ...

Related

My ionic app wont connect to a MYSQL database running on the phone but on the PC with localhost it will run

I made an ionic app with a connection to MYSQL using a PHP API which I put on another computer on Xampp, using it as a remote server in the same network, when I run it on the computer with ionic serve , it works fine but when I generate the APK, it wont connect to the BD, even tho Im on the same network, does someone knows any way around this?
this is how it looks on the desktop
and this is how it looks on the cellphone
What I would conclude is that it connects to the nodejs server ("ionic serve") to load the assets from there but it cannot load data from the php/mysql API.
How did you reach the conclusion that MySQL is the problem? I mean your frontend (angular) does connect directly to MySQL right?
Hint: check your settings within ionic when you call the API -- it should point NOT to localhost/127.0.0.1 but to your computer's network IP. Apache should also be "open" to connections from "outside":
see here: Accessing localhost (xampp) from another computer over LAN network - how to?
I had the same problem in the past, it is because when you run the application on your pc it is working on localhost, just like your backend. When you run your application on a mobile device, it does not have access to your pc using localhost to access the backend.
In this case you must set the IP that your pc has on your local network as the backend address and in this way your mobile application can access it

Localhost and Android Connection

Let's say I'm developing application on my laptop. I have connection to the localhost, and created database. Will I be able to store, or extract data when I run my application on my phone? The phone is not connected to the laptop.
Yes:
Your phone and laptop connected to same LAN (minimal example: set your phone as router with mobile hotspot and connect your development laptop to it).
In other words simply connect the phone and PC running the server to the same local network.
if you have puplic ip you can even let others test your app and connect to your pc as server (preferred static but dynamic will work as well but you have to monitor it and change it in your app every time it changes but most of the time it stays for hours if its not a moving mobile).
Edit:
For php apps you can install a php server in your android phone like Palapa Web Server (tested) and then in your app just make your calls to local address.

Connecting local php server with android devices

To connect local php website, i was able to connect from another pc in the same network by using ipaddress/foldername (eg. 192.168.1.1/test). I want to know that can i connect from android phone in the same wifi using the same method.
You could also use ngrok for this:
https://ngrok.com/
ngrok allows you to create a globally accessible domain name which directs to your local pc, especially useful for development.
As your device in the same local network, it will connect to your local website on your way

android sensor programe to send data to local database

I have android program to display the sensor data and on button click it will send to local MySQL database running with PHP as backed in wamp server.its working properly.to connect to database i have given local host or local IP address of the system which is running. now i want to send the data to same database on button click with any network connected ? what should i do ? I even tried change allow access to all edit alias in wamp server but unable to connect. so any one suggest what to do?
thanks in advance
Make sure your android app and the computer on which your php code is running are all in the same network. To do this all you can do is create wifi hotspot using one of the devices and connect the other to the same wifi (Create hotspot in your mobile, which is running the app and connect your computer to the same wifi hotspot. Next open command prompt and execute ipconfig. Use the IP address that you got when you connected your computer to mobile hotspot).
OR
You can host your backend code on some servers and use the IP address in your android app(This is more as useful as you can use your android app from any network)

Connecting Android device to Apache server

I have created a database and trying to access it using php. I execute these scripts from my phone. Now the issue is that when I try to perform any operation on the DB from the real device (my MOBILE PHONE) it says "unfortunately Closed" but works fine from the virtual device.
URL for real android device:
[http:// 127.0.0.1:8888 //android_connect/get_product_details.php]
URL for the virtual device:
[http:// 10.0.2.2 /android_connect/get_product_details.php]
The 127.0.0.1 is a loopback address so the android device or any other computer will not able to connect to it. Get a webserver (there's a lot freely available to test PHP scripts) , drop all the files in there and you will be able to access it.
say.. http://somefreewebhost.com/android_connect/get_product_details.php
Alternatively...
If you are using a webserver like WAMP, you will have an option called "Put Online". Go to your command prompt and type "ipconfig" and note down that IP address and you can even use that (provided if you are not behind any firewall)

Categories