Reputation:
i'm trying to list the elements of a MySQL database using AngularJS. Despite some research, i can't find what to write in the controller function to do that.
To be more precise, i previously did it without AngularJS using the following :
$link = new PDO('mysql:host=localhost;dbname=mygaloo;charset=utf8', 'root', '');
$query = $link->query("SELECT * FROM ".$choice." WHERE nom LIKE '%".$request."%' ORDER BY id DESC");
Here's my current code :
<div ng-app="searchApp" ng-controller="searchController">
<table>
<tr ng-repeat="x in objects">
<td>{{ x.name }}</td>
</tr>
</table>
</div>
<script>
var app = angular.module('searchApp', []);
app.controller('searchController', function($scope)
{
//What should i do here ?
});
</script>
Upvotes: 0
Views: 1305
Reputation: 1382
I'm not sure this will work. Because it shouldn't.
There is a distinct difference between client-side and server-side programming.
Angular and jQuery are run client-side, or, on the clients computer. This means, when you do something like this:
$link = new PDO('mysql:host=localhost;dbname=mygaloo;charset=utf8', 'root', '');
All the data needed to browse your database is given to the user. Hell, you provided the root. This means that anyone can simply log on to your database as root, and modify everything in your database, or simply collecting all userdata.
To secure this you need to do some server-side scripting, and an API to expose data to the application.
Server-side code is never exposed to the client, this makes it a good place to store passwords and make connections to your databases. There are many possibilities for client-side scripting.
Just pick one, and start reading up on how to use them.
Upvotes: 3