Is there a way to access a MySql database using entirely client side Javascript or do you need to go through a server side language such as PHP or C#?
Thanks
JavaScript is a client-side language that runs in the browser and MySQL is a server-side technology that runs on the server. You need to use the server-side language Node. js to connect to the MySQL Database.
JavaScript can't directly access the database. You'll need to have some server-side component that takes requests (probably via HTTP), parses them and returns the requested data.
No you can't interact with MySQL through JavaScript or JQuery. You could use JavaScript and JQuery through your PHP pages if that would be a functionality you'd be interested in. You could also use another language compatible with MySQL. Otherwise interacting with MySQL straight through JavaScript/JQuery won't work.
To access a specific database, type the following command at the mysql> prompt, replacing dbname with the name of the database that you want to access: Copy use dbname; Make sure you do not forget the semicolon at the end of the statement. After you access a database, you can run SQL queries, list tables, and so on.
Javascript, if run in the browser, has no way of accessing a MySQL Database. For one, this is a technical limitation, because Javascript has no way of communicating arbitrary protocols (no, WebSockets are not the solution). Note that Node.js, being server side and all, is a "different kind of javascript".
Then there is the security issue. If your javascript could access the database directly, I could easily access the database myself. I would be able to read and manipulate the same data your javascript can. Security-wise calling this a nightmare would be an euphemism.
You'll have to - and WANT TO - route database access through a server side application. If that app is written in PHP, C# or Assembly doesn't really matter much. With Node.js you can even use Javascript on the server side. Use what you're comfortable with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With