Communication between ionic and local server


I develop an ionic application that communicates with a database stored on my computer.

when i run my application on my machine with the command ionic lab, any function perfectly but when i install the apk on a mobile, i have the message unable to connect to the server.
how can I fix this error


What is the exact and complete error message?
How is your app talking to your server?


the error that appears on the phone is:
“Application error
the connection to the server was unsuccessfull
file: ///android_asset/www/index.html

I connect my application to the server with php and I use this statement “this.http.get (” http: //localhost/sw/connexion.php “);” to connect to the database.

the contents of the connection.php file is as follows:

<? Php // Define database connection parameters $ hn = 'localhost'; $ a = 'root'; $ pwd = ''; $ db = 'sw'; $ cs = 'utf8'; // Set up the PDO parameters $ dsn = "mysql: host =". $ hn. "; port = 3306; dbname =". $ db. "charset =". $ Cs; $ opt = array ( PDO :: ATTR_ERRMODE => PDO :: ERRMODE_EXCEPTION, PDO :: ATTR_DEFAULT_FETCH_MODE => PDO :: FETCH_OBJ, PDO :: ATTR_EMULATE_PREPARES => false, ); // Create a PDO instance (connect to the database) $ pdo = new PDO ($ dsn, $ un, $ pwd, $ opt); ?>


I think when the app run on your phone localhost is not the right name of the server because the server runs not on your phone right?

Change localhost to the ip of your machine or the network name of your machine. Make sure that your phone and machine is in the same network.

If I run ionic serve it shows me something like this:


Use the external information.


Search the forum and or google for this error message. This indicates that the Cordova app being generated can not open your Ionic app running inside it. What device are you testing on? Do you have a newer, faster one? If not, there is a timeout value you can set - searching for that error message should give it to you quite easily.