Html 如何将网站连接到MYSQL数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19001271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to connect Website to MYSQL database?
提问by Dahdoul
Am currently working on a website(html 5) that calculate the expenses for the user, after the calculation, user has to save it as report for future purposes. So i wanna know if there is anyway to connect the website to MYSQL database or any alternative way rather than create database using java script because am a novice on Js.
我目前正在一个网站(html 5)上计算用户的费用,计算后,用户必须将其保存为报告以备将来使用。所以我想知道是否有任何方法可以将网站连接到 MYSQL 数据库或任何其他方式,而不是使用 java 脚本创建数据库,因为我是 Js 的新手。
thankyou
谢谢你
采纳答案by Arvind Sridharan
ideally you should be writing some server side code to add this sort of information to a database. that way you can secure access to authorised users (i.e. logged in users) and your queries cannot be modified on the browser by any user. you can use a programming language like PHP (with a framework like Yii, CodeIgniter) which is quite lightweight.
理想情况下,您应该编写一些服务器端代码来将此类信息添加到数据库中。这样您就可以确保对授权用户(即登录用户)的访问安全,并且任何用户都无法在浏览器上修改您的查询。你可以使用像 PHP 这样的编程语言(带有像 Yii、CodeIgniter 这样的框架),它非常轻量级。
回答by Quentin
Browsers have no built in mechanisms for connecting to a MySQL server.
浏览器没有用于连接到 MySQL 服务器的内置机制。
Your options are:
您的选择是:
- Write a browser plugin
- Write a web service and use JavaScript to create an XMLHttpRequest object to communicate with it
- 编写浏览器插件
- 编写一个 Web 服务并使用 JavaScript 创建一个 XMLHttpRequest 对象来与之通信
The second option is the most common one (and almost certainly the best since it doesn't require that the user install a browser plugin or that you give direct access to the database to all your users).
第二个选项是最常见的选项(几乎可以肯定是最好的选项,因为它不需要用户安装浏览器插件或让所有用户直接访问数据库)。
If you want to use JavaScript, then you can create your web service with (for example) Node.jsand the mysql driver in npm.
如果您想使用 JavaScript,那么您可以使用(例如)Node.js和npm 中的mysql 驱动程序创建您的 Web 服务。
回答by Mayank Sharma
You should use HTML5 Web SQL for this purpose. Here is link you can refer to: http://www.tutorialspoint.com/html5/html5_web_sql.htm
为此,您应该使用 HTML5 Web SQL。这是您可以参考的链接:http: //www.tutorialspoint.com/html5/html5_web_sql.htm