-1

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? enter image description here

this is how it looks on the desktop

and this is how it looks on the cellphone enter image description here

Alejandro
  • 9
  • 1
  • 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? – Hop hop Nov 22 '21 at 07:35
  • We can't fix pictures. Please provide relevant code and debugging data. See [ask] and how to create a [mre] for guidance. – ADyson Nov 22 '21 at 07:46

2 Answers2

0

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?

Hop hop
  • 841
  • 8
  • 21
  • I think is more of a Xampp problem or my network, that what I'm not sure, the MYSQL run fine and as you said, if its on a localhost it can do the connection to it, on my PHP side, when I do the connection I have it like this: private URL_API: string = 'http://192.168.197.90/API/'; which is the IP where I have the server on and here is where I make the petitions Producto_Listado(_texto: string = '') { return this.http.post(this.URL_API + 'listado-productos', this.objectToFormData({ texto: _texto })); } frome there, I do the request to the PHP side of the app – Alejandro Nov 22 '21 at 16:46
  • can you open https://192.168.197.90/API in your phone browser? does it "load" correctly? what about http://192.168.197.90/API ? (HTTP, not HTTPS) – Hop hop Nov 25 '21 at 17:43
0

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

rbarbeitor
  • 146
  • 1
  • 6