使用 mysqli & 将数百条记录插入 mysql 数据库PHP

发布于 2024-11-09 23:31:30 字数 517 浏览 2 评论 0原文

我正在制作一个 Flex 4 应用程序并使用 ZendAMF 与 MySQL 数据库交互。我让 Flex 为我生成了大部分服务代码(它使用了 mysqli),并粗略地编辑了一些代码(对于 PHP,我还是个新手)。此时一切正常。

我的问题是 - 目前,应用程序在创建用户时将大约 400 条记录插入数据库(它保存自己的数据供他们稍后加载),但它是通过单独调用服务器来实现这一点的 - 即每条记录发送到服务器,然后保存到数据库,然后发送下一条记录。

这在我的本地环境中运行良好,但由于使用实时网络服务器,它只在某些时候添加这些记录。其他时候它会完全忽略它。 我假设它这样做是因为实时数据库不喜欢几乎同时收到数百个请求的垃圾邮件

我认为更有效的方法是将所有这些记录打包到一个数组,将其发送到服务器一次,然后让 PHP 服务对数组中的每个项目执行多次插入。问题是,我不知道如何使用 mysqli 语句在 PHP 中进行编码

任何帮助或建议将不胜感激 - 谢谢!

I'm making a Flex 4 application and using ZendAMF to interact with a MySQL database. I got Flex to generate most of the services code for me (which utilizes mysqli) and roughly edited some of the code (I'm very much a novice when it comes to PHP). All works fine at this point.

My problem is - currently the application inserts ~400 records into the database when a user is created (it's saving their own data for them to load at a later date) but it does this with separate calls to the server - i.e. each record is sent to the server, then saved to the database and then the next one is sent.

This worked fine in my local environment, but since going on a live webserver it only adds these records some of the times. Other times it will totally ignore it. I'm assuming it's doing this because the live database doesn't like getting spammed with hundred of requests at practically the same time

I'm thinking a more efficient way would be to package all of these records into an array, send that to the server just the once and then get the PHP service to do multiple inserts on each item in the array. The problem is, I'm not sure how to go about coding this in PHP using mysqli statements.

Any help or advice would be greatly appreciated - thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

じее 2024-11-16 23:31:30

Read up on LOAD DATA LOCAL INFILE. It seems it's just what you need for inserting multiple records: it inserts many records from a file (though not an array, unfortunately) into your table in one operation.

It's also much, much faster to do multiple-record UPDATEs with LOAD DATA LOCAL INFILE than with one-per-row UPDATEs.

吃颗糖壮壮胆 2024-11-16 23:31:30

ee 你应该单独处理用户默认值,只存储更改

,如果没有保存,你必须检查 mysql 的警告或 php 的错误,数据不会消失,

尝试

error_reporting(-1);

请在插入之前
以及

mysqli::get_warnings()

此后

ee you should handle the user defaults separate and only store the changes

and if they are not saved you must check warnings form mysql or errors form php, data don't disappear

try

error_reporting(-1);

just before insering
and

mysqli::get_warnings()

aferwards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文