Javascript 和数据库连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5521968/
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
Javascript and Database Connectivity
提问by Ashwin Krishnamurthy
Is it possible for javascript to access a database directly? I feel my question is rhetorical owing to the fact that this is a security issue. But is it possible anyway?
javascript可以直接访问数据库吗?我觉得我的问题是修辞性的,因为这是一个安全问题。但无论如何这可能吗?
回答by gion_13
It is possible!
with the new html5 feature, js can connect through WebSql.
a live example : http://html5demos.com/database
the syntax is similar to all the other sql wrappers :
有可能的!
有了新的 html5 特性,js 可以通过 WebSql 连接。一个活生生的例子:http: //html5demos.com/database
语法类似于所有其他 sql 包装器:
var db = openDatabase('mydb', '1.0', 'my first database', 2 * 1024 * 1024);
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE foo (id unique, text)');
});
it is currently supported by chrome, safari and opera
here's a tutorial : http://html5doctor.com/introducing-web-sql-databases/
它目前受 chrome、safari 和 opera 支持,
这里有一个教程:http: //html5doctor.com/introducing-web-sql-databases/
回答by Darin Dimitrov
Is it possible for javascript to access a database directly?
javascript可以直接访问数据库吗?
No. Setup a server side script which will talk the database and then call this script with AJAX.
不。设置一个服务器端脚本,它将与数据库对话,然后使用 AJAX 调用此脚本。
回答by Daniel Willis
Depends on what DB you want to use.
取决于您要使用的数据库。
CouchDB is HTTP addressable, so can be hit from JS. http://couchdb.apache.org/
CouchDB 是 HTTP 可寻址的,因此可以从 JS 中命中。http://couchdb.apache.org/
回答by picardo
Not from the browser. Javascript can be used on the serverto set up server side functionality, though.
不是来自浏览器。不过,可以在服务器上使用 Javascript来设置服务器端功能。
回答by Mahesh
Yes it is.
是的。
I don't know more about it but javascript can connect with DB using ADODB.Connection.
我不知道更多,但 javascript 可以使用 ADODB.Connection 与 DB 连接。
回答by user2775850
http://www.daniweb.com/web-development/php/threads/197091/update-mysql-table-using-javascriptYou need to look into the jQuery.ajax function, this will send/receive information from a PHP document.
http://www.daniweb.com/web-development/php/threads/197091/update-mysql-table-using-javascript您需要查看 jQuery.ajax 函数,这将发送/接收来自 PHP 文档的信息.
What you need to do is set up a PHP document that will handle the the form as though it were being posted to by http, or by setting the action on the tag.
您需要做的是设置一个 PHP 文档,该文档将处理表单,就像它是通过 http 发布的一样,或者通过在标签上设置操作。
You then need to make a function similar to this:
然后,您需要创建一个与此类似的函数: