I have this error when I’m testing my ionic app in a real device, Error: Failed to load resource and the link to my php script which supposedly retrieves/displays the record from MySQL. But when I’m doing ionic serve
the records are displayed.
i.e.
But when I do ionic cordova run android
or if emulated, nothing is shown but ionic app is launched but the Menu shows no records.
Here’s the php code anyway,
<?php
header('Access-Control-Allow-Origin:*');
$hn='localhost';
$un='root';
$pwd='';
$db='orderingsystem';
$cs='utf8';
$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);
$data = array();
// Attempt to query database table and retrieve data
try {
$stmt=$pdo->query('SELECT * FROM tblproducts ORDER BY PRODUCT_CODE ASC');
while($row = $stmt->fetch(PDO::FETCH_OBJ))
{
// Assign each row of data to associative array
$data[] = $row;
}
// Return data as JSON
echo json_encode($data);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
Please help me, thank you so much!