How to use Javascript to manipulate data from the database? [closed]

3

I'm now starting to deal with web development in PHP. We know that to have an efficient and dynamic system, it is advisable to use JavaScript, such as, JQuery, AngularJS, Backbone.js and others. But from what I know of Javascipt, it does not have an API to connect to the database.

I have a system to develop in PHP to manipulate data from the database. In this case I need to "get" the data in the database and generate a graph, using for example the Google Charts API. The first thing I thought of is to manipulate JavaScript code with PHP, ie put the tags JavaScript inside the PHP code (code to connect to the database) and get the data and insert it in Javascript. However, this would not be a good programming practice, as my code would be unreadable to handle and I would have future problems with my system.

I would like to get experienced programmers on how to get around this situation. Basically, how can I manipulate data from the database in JavaScript, AngularJS, Google Charts and etc. and how can I get a good integration between PHP and JavaScript programming, as well as other languages with JavaScript.

    
asked by anonymous 20.11.2015 / 12:16

1 answer

6

I think you're putting the car in front of the oxen. You do not choose the technology you're going to use, and then see what problem you're going to solve. So he made the initial statement that it has no meaning: "We know that to have an efficient and dynamic system, it is advisable to use JavaScript, such as JQuery, AngularJS, Backbone.js and others." This is completely incorrect. Just because you think technology is important.

JavaScript can even be used to access a local "database", but it's probably not what you want. JS can also be used through Node.js on the server to access a database, but it is not what you want either.

So if you are going to access a database on the server, do it with PHP and establish communication between the client and the server with web technologies. If JS can (and is not always right) to help give a better experience in this communication, then use it on the client to facilitate.

Make sure you do not put any JS inside PHP. You just put some text in PHP, which you happen to know is a JS code. But this will be sent to the client and will not be executed by PHP. It is not a question of being unreadable, it is not doable. In addition to being illegible and extraneous.

First ensure that the server side is getting the data it needs. Then do a basic test where the customer picks up this data in the simplest way possible, only using HTML. Then start refining using techniques where JavaScript is used, with or without frameworks .

As the question is full of false premises, it is difficult to help more, but it is possible to post new questions with specific questions in each step of the desired solution.

    
20.11.2015 / 12:27