I'm working with angularJS, a project created with YEOMAN-Generator!
and I need to consult a database.
I thought I could integrate php
with a simple query but it still does not leave me. As I did? Well, here's the code:
Inside the folder app I created a folder called php and in it create a file that I called conection that contains the connection:
<?php
$con = mysqli_connect("localhost", "root", "", "saltala");
?>
and another file called query.php :
<?php
require_once 'conection.php';
$query = "SELECT rut, numero, servicio_id FROM Tickets";
$result = mysqli_query($con, $query);
$arr = array();
if(mysqli_num_rows($result) != 0) {
while($row = mysqli_fetch_assoc($result)) {
$arr[] = $row;}
}
echo $json_info = json_encode($arr);
?>
and in the controller folder where the project drivers are located, create the following code:
// comienza la conexion
getInfo();
function getInfo(){
$http.post('php/consulta.php').success(function(data){
$scope.details = data;
console.log(data);
})};
// finaliza la conexion
First run with gulp serve
and you did not recognize at all the php
, so change the location of the project folder to htdocs within xampp and I executed it and I threw the data I needed!.
Greetings.