Query and modify data from MySQL with VueJS?
Hello, I have a MySQL database on our school's server. Now I want to query and edit data from this database using VueJS. Unfortunately, I haven't been able to find any good videos or documentation online. How can I implement my plan?
There are two usual options to send data to a backend, since on the one hand the fetch function installed in JS would be. With this one would normally send a POST request to the backend and the corresponding data with attachments. Alternatively, there is the Axios library that has similar functionality.
If you use a PHP backup (and this can be a single file), you can find the data sent from the frontend in the $_POST variable and work with it.
Important: With such things, you always have to assume that even unexpected things or nothing are in $_POST, so always check whether there is anything in it at all, and if you work with a database, make sure that no SQL injection is possible.
In the PHP file you can then work for example with the built-in mysqli class to write the data into the database.
https://www.php.net/manual/de/mysqli.quickstart.php
It’s not for good reason. The query of data is done server-side. JavaScript and JS-Frameworks have no way to implement the client-side. That would be a security risk. There are languages such as Python or PHP that can retrieve the data and send it to the script via request.
I put it wrong. I’m trying to call VueJS exactly something like a PHP script that takes over this task for me. I have some variables in the VueJS that I want to write to a database using PHP, for example.
Hi, no problem. Using HTTP requst or with fetch, asynchronous data can be retrieved from the server. The PHP page is called and the data is output. Before that you can send data to this PHP file. This is then received by the POST method or GET method and can be further processed. As a result, the required data is sent back as a request. I am Hater of VueJS, but went away from Corona from JavaScript-Frameworks and have gathered for the most part positive experiences but I would like to write you a solution in VueJS: https://www.w3schools.com/vue/vue_http.php and https://test-utils.vuejs.org/guide/advanced/http-requests I wish you a lot of success and if you have more questions, just write on.
VueJS is actually only for front-end, although there are embedded databases, but they are all only in the memory and MySQL you won’t get there.
You should do everything to databases in the backend.
you need a backend which then communicates with the front end