I'm not able to call the database with the method below:
<div class="container" ng-app="appCat">
<div class="row" ng-controller="appCatCtrl">
<table class="table table-striped">
<tr>
<th>Nome</th>
<th>Telefone</th>
</tr>
<tr ng-repeat="x in category">
<td>{{x.cat}}</td>
<td>{{x.sub}}</td>
</tr>
</table>
</div>
</div>
In the JS file:
angular.module("appCat", []);
angular.module("appCat").controller("appCatCtrl", function ($scope, $http) {
$scope.category = [];
var showCat() {
$http.get("proc_cat.php").then(function(response) {
$scope.category = response.data;
});
}
showCat();
});
and in PHP:
try {
$con = new PDO($dns, $user, $pass);
if(!$con){
echo "Não foi possivel conectar com Banco de Dados!";
}
$query = $con->prepare('SELECT * FROM category');
$query->execute();
$out = "[";
while($result = $query->fetch()){
if ($out != "[") {
$out .= ",";
}
$out .= '{"cat": "'.$result["name_cat"].'",';
$out .= '"sub": "'.$result["sub_cat"].'"}';
}
$out .= "]";
echo utf8_encode($out);
} catch (Exception $e) {
echo "Erro: ". $e->getMessage();
};