php 如何构建一个离线工作的php mysql应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12272302/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:11:32  来源:igfitidea点击:

how to build a php mysql application that works offline

phpmysqloffline

提问by user1536396

I have a web applications that stores data in a MySQL database on-line. It also retrieves data using PHP code, performs calculations on the server and sends the result back to the user.

我有一个 Web 应用程序,可以在线将数据存储在 MySQL 数据库中。它还使用 PHP 代码检索数据,在服务器上执行计算并将结果发送回用户。

Data it's quite simple: names, descriptions, prices, VAT, hourly charges that are read from the database and manipulated on the server side.

数据非常简单:从数据库中读取并在服务器端操作的名称、描述、价格、增值税、小时费用。

Often client work in environments where the internet connection is poor or not available. In this case I would like the client to be able to work offline: enter new names, descriptions, prices and use the last VAT to perform calculations. Then synchronise all data as soon as a connection is available.

客户通常在互联网连接较差或不可用的环境中工作。在这种情况下,我希望客户能够离线工作:输入新名称、描述、价格并使用最后的增值税来执行计算。然后在连接可用时立即同步所有数据。

Now the problem is that I do not know what is the best way or technologies for achieving this. Don't worry, I am not asking to write code for me. Can you just explain to me what is the correct way to build such a system?

现在的问题是我不知道实现这一目标的最佳方法或技术是什么。别担心,我不是要为我写代码。你能向我解释一下构建这样一个系统的正确方法是什么吗?

Is there a simple way to use my online MySQL and PHP code locally?

有没有一种简单的方法可以在本地使用我的在线 MySQL 和 PHP 代码?

Should I save the data I need in a local file, rebuild the calculation in JavaScript, perform them locally and then synchronise the data if database is available.

我是否应该将我需要的数据保存在本地文件中,在 JavaScript 中重建计算,在本地执行它们,然后在数据库可用时同步数据。

Should I use two MySQL database, one local and one online and do a synchronisation between the two when data is available? If yes which technology (language) shall I use to perform this operation?

我应该使用两个 MySQL 数据库,一个是本地的,一个是在线的,并在数据可用时在两者之间进行同步吗?如果是,我应该使用哪种技术(语言)来执行此操作?

If possible, I would like an answer from PHP coders that worked on a similar project in the past and can give me detailed information on framework structure and technology to use. please remember that I am new to this way of writing application and I would appreciate if you can spare few minutes and explain everything to me like if I am six year old or stupid (which I am!)

如果可能的话,我希望从过去从事过类似项目的 PHP 编码人员那里得到答案,并且可以为我提供有关框架结构和要使用的技术的详细信息。请记住,我是这种编写应用程序方式的新手,如果您能抽出几分钟时间向我解释一切,就像我六岁或愚蠢(我是!)

I really appreciate any help and suggestion.

我非常感谢任何帮助和建议。

Ciao,

再见,

Donato

多纳托

回答by Eugen Rieck

There are essentially 3 ways to go:

基本上有3种方法:

Version 1: "Old school": PHP-Gtk+ and bcompiler

版本 1:“老派”:PHP-Gtk+ 和 bcompiler

  • first, if you not have done so already, you need to separate your business logic from your presentation layer (HTML, templating engines, ...) and database layer
  • then adapt your database layer, so that it can live with an alternative DB (local SQlite comes to mind) and perform synchronisation when online again
  • Finally use PHP-Gtk+ to create a new UI and pack all this with bcompiler
  • 首先,如果您还没有这样做,您需要将业务逻辑与表示层(HTML、模板引擎等)和数据库层分开
  • 然后调整您的数据库层,以便它可以使用替代数据库(想到本地 SQlite)并在再次联机时执行同步
  • 最后使用 PHP-Gtk+ 创建一个新的 UI 并用 bcompiler 打包所有这些

Version 2: "Standard": Take your server with you

版本 2:“标准”:随身携带服务器

  • Look at Server2Go, WampOnCD and friends to create a "double clickable webserver" (Start at Z-WAMP)
  • You still need to adapt your DB layer as in Version 1
  • 看 Server2Go、WampOnCD 和朋友们创建一个“可双击的网络服务器”(从Z-WAMP开始)
  • 您仍然需要像版本 1 一样调整您的数据库层

Version 3: "Web 2.x": Move application from server to browser

版本 3:“Web 2.x”:将应用程序从服务器移动到浏览器

  • Move your application logic from the server side (PHP) to the client side (JS)
  • Make your server part (PHP) only a data access or sync layer
  • Use the HTML5 offline features to replace your data access with local data if you are offline and to resync if online
  • 将您的应用程序逻辑从服务器端 (PHP) 移至客户端 (JS)
  • 使您的服务器部分 (PHP) 仅成为数据访问或同步层
  • 如果您处于离线状态,则使用 HTML5 离线功能将数据访问替换为本地数据,并在在线状态下重新同步

Which one is best?

哪一个最好?

This depends on what you have and what you want. If most of your business logic is in PHP, then moving it into the browser might be prohibitingly expensive - be aware, that this also generates a whole new class of security nightmaares. I personally do not recommend portingthis way, but I do recommend it for new apps, if the backing DB is not too big.

这取决于您拥有什么和想要什么。如果您的大部分业务逻辑都在 PHP 中,那么将其移入浏览器的成本可能高得惊人——请注意,这也会产生全新的安全噩梦。我个人不建议以这种方式移植,但如果后备数据库不是太大,我建议将它用于新应用程序。

If you chose to keep your PHP business logic, then the desicion between 1 and 2 is often a quiestion of how much UI does your app have - if it's only a few CRUD forms, 1. might be a good idea - it is definitly the most portable (in the sense of taking it with you). If not, go with 2.

如果你选择保留你的 PHP 业务逻辑,那么 1 和 2 之间的决定通常是你的应用程序有多少 UI 的问题 - 如果它只有几个 CRUD 表单,1. 可能是一个好主意 - 它绝对是最便携(在随身携带的意义上)。如果没有,请选择 2。

回答by Ben D

Have a look at HTML5's application cache. That's pretty much what it's for. There are plentyoftutorialsaround for this, so have a look around and see if it suits your needs.

看看 HTML5 的应用程序缓存。这几乎就是它的用途。有很多关于这方面教程,所以看看周围,看看它是否适合你的需求。

回答by Juris Malinens

I have worked with similar system for ships. Internet is expensive in the middle of the ocean so they have local web servers installed with database synchronization via e-mail.

我曾使用过类似的船舶系统。大洋中的互联网价格昂贵,因此他们安装了本地网络服务器,并通过电子邮件进行数据库同步。

We also have created simple .exe packages so people with no experience can install the system or update system...

我们还创建了简单的 .exe 包,以便没有经验的人可以安装系统或更新系统...