Home > Back-end >  My ionic app wont connect to a MYSQL database running on the phone but on the PC with localhost it w
My ionic app wont connect to a MYSQL database running on the phone but on the PC with localhost it w

Time:12-04

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

CodePudding user response:

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?

CodePudding user response:

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

  • Related