Can JavaScript connect with MySQL?

前端 未结 19 2112
小鲜肉
小鲜肉 2020-11-22 16:18

Can JavaScript connect with MySQL? If so, how?

19条回答
  •  孤街浪徒
    2020-11-22 16:41

    Typically, you need a server side scripting language like PHP to connect to MySQL, however, if you're just doing a quick mockup, then you can use http://www.mysqljs.com to connect to MySQL from Javascript using code as follows:

    MySql.Execute(
        "mysql.yourhost.com", 
        "username", 
        "password", 
        "database", 
        "select * from Users", 
        function (data) {
            console.log(data)
    });
    

    It has to be mentioned that this is not a secure way of accessing MySql, and is only suitable for private demos, or scenarios where the source code cannot be accessed by end users, such as within Phonegap iOS apps.

提交回复
热议问题