P粉9211651812023-08-21 13:56:07
Client-side JavaScript cannot access MySQL directly unless there is some kind of bridge. But the statement in the bold statement above that JavaScript is only a client-side language is incorrect - JavaScript can run both client-side and server-side, such as Node.js.
Node.js can access MySQL through a method similar to https://github.com/sidorares/node-mysql2.
You can also develop something using Socket.IO.
Do you want to ask whether the client JS application can access MySQL? I'm not sure if such a library exists, but it's possible.
EDIT: Since writing this we now have MySQL Cluster:
JSDB Provides a JS interface to access the database.
A curated collection of database packages for Node.js from sindresorhus.
P粉2957286252023-08-21 00:43:15
No, JavaScript can not directly connect to MySQL. But you can mix JS with PHP to do so.
JavaScript is a client-side language, while your MySQL database will run on the server.