如何使用javascript将数据存储到mysql数据库?

时间:2022-09-27 16:23:20

I'm still pretty new to AJAX. We have a MySQL database that stores addresses for people who register with the site. We then use those stored addresses to create markers on a Google Map (API v3) through a JSON query. The problem is, that's pretty slow, and limited in the number of queries we're allowed. So we've created fields in the database to store the latitude and longitude that is being called by JSON.

我还是AJAX的新手。我们有一个MySQL数据库,可以为注册该站点的人员存储地址。然后,我们使用这些存储的地址通过JSON查询在Google Map(API v3)上创建标记。问题是,这很慢,并且我们允许的查询数量有限。所以我们在数据库中创建了字段来存储JSON调用的纬度和经度。

Through each pass of the loop, the numbers can be retrieved through

通过循环的每次传递,可以检索数字

result[0].geometry.location.lat() result[0].geometry.location.lng()

result [0] .geometry.location.lat()result [0] .geometry.location.lng()

How do I take those numbers and store them into their empty fields in the database?

如何获取这些数字并将它们存储到数据库中的空白字段中?

2 个解决方案

#1


4  

Javascript runs on the client/browser side - its not a good idea to give that access to your mysql-server/databases.

Javascript在客户端/浏览器端运行 - 提供对mysql-server / databases的访问权限并不是一个好主意。

Just use some server-side logic (php) for that.

只需使用一些服务器端逻辑(php)。

Heres an example from W3 retrieving data via AJAX and PHP, just change to updating stuff

下面是W3通过AJAX和PHP检索数据的一个例子,只是更改为更新内容

http://www.w3schools.com/php/php_ajax_database.asp

http://www.w3schools.com/php/php_ajax_database.asp

#2


2  

You can send data to a server with javascript, but you need a library to interact with a database system, so on the server you will usually process that data and send commands to store it in the database. In PHP the support for MySQL is built-in so you have functions and objects to connect to the database simply like mysql_XXXX or through a PDO object.

您可以使用javascript将数据发送到服务器,但是您需要一个库来与数据库系统进行交互,因此在服务器上,您通常会处理该数据并发送命令将其存储在数据库中。在PHP中,对MySQL的支持是内置的,因此您可以像使用mysql_XXXX或通过PDO对象一样连接数据库。

http://php.net/manual/en/book.pdo.php

http://php.net/manual/en/book.pdo.php

#1


4  

Javascript runs on the client/browser side - its not a good idea to give that access to your mysql-server/databases.

Javascript在客户端/浏览器端运行 - 提供对mysql-server / databases的访问权限并不是一个好主意。

Just use some server-side logic (php) for that.

只需使用一些服务器端逻辑(php)。

Heres an example from W3 retrieving data via AJAX and PHP, just change to updating stuff

下面是W3通过AJAX和PHP检索数据的一个例子,只是更改为更新内容

http://www.w3schools.com/php/php_ajax_database.asp

http://www.w3schools.com/php/php_ajax_database.asp

#2


2  

You can send data to a server with javascript, but you need a library to interact with a database system, so on the server you will usually process that data and send commands to store it in the database. In PHP the support for MySQL is built-in so you have functions and objects to connect to the database simply like mysql_XXXX or through a PDO object.

您可以使用javascript将数据发送到服务器,但是您需要一个库来与数据库系统进行交互,因此在服务器上,您通常会处理该数据并发送命令将其存储在数据库中。在PHP中,对MySQL的支持是内置的,因此您可以像使用mysql_XXXX或通过PDO对象一样连接数据库。

http://php.net/manual/en/book.pdo.php

http://php.net/manual/en/book.pdo.php

相关文章