Can JavaScript connect with MySQL? If so, how?
相关问题
- Is there a limit to how many levels you can nest i
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- How to toggle on Order in ReactJS
- StackExchange API - Deserialize Date in JSON Respo
JavaScript can't connect directly to DB to get needed data but you can use AJAX. To make easy AJAX request to server you can use jQuery JS framework http://jquery.com. Here is a small example
JS:
PHP:
Bit late but recently I have found out that MySql 5.7 got http plugin throuh which user can directly connect to mysql now.
Look for Http Client for mysql 5.7
Client-side JavaScript cannot access MySQL without some kind of bridge. But the above bold statements that JavaScript is just a client-side language are incorrect -- JavaScript can run client-side and server-side, as with Node.js.
Node.js can access MySQL through something like https://github.com/sidorares/node-mysql2
You might also develop something using Socket.IO
Did you mean to ask whether a client-side JS app can access MySQL? I am not sure if such libraries exist, but they are possible.
EDIT: Since writing, we now have MySQL Cluster:
Depending on your environment, you could use Rhino to do this, see Rhino website. This gives you access to all of the Java libraries from within JavaScript.
No, JavaScript can not directly connect to MySQL. But you can mix JS with PHP to do so.
JavaScript is a client-side language and your MySQL database is going to be running on a server
You can add mysql connection using PHP file. Below is the example of PHP file.