简体   繁体   English

从SQLite3数据库动态获取/设置列的最佳方法?

[英]Best way to get/set columns dynamically from a SQLite3 database?

...or I really need to create a class for each Table? ...或者我真的需要为每个表格创建一个类吗? then.. everytime i changes table structure i need to update the code.. 然后..每次我更改表结构时,我需要更新代码。

You could use an ORM (Object-relational mapper) such as Eloquent, which is included in Laravel , and then just create an model (class) for each table in your database. 您可以使用Laravel中包含的ORM(对象关系映射器),例如Eloquent ,然后为数据库中的每个表创建一个模型(类)。 Eloquent automatically maps each field into a PHP object. Eloquent自动将每个字段映射到一个PHP对象。 If you haven't ever used an ORM, I highly recommend you check out Laravel... it's what made me stick with PHP and I do almost all my projects using Laravel. 如果您从未使用过ORM,我强烈建议您检查Laravel ...这就是让我坚持使用PHP的原因,并且几乎所有我的项目都使用Laravel进行。 Best of luck! 祝你好运!

Adding to BakerStreet Response. 添加到BakerStreet响应。

Eloquent fits your needs as the ORM itself will fetch all the columns you specify if you leave it as default. Eloquent符合您的需求,因为如果您将其保留为默认值,那么ORM本身将获取您指定的所有列。 By default the drivers that it works with are: mysql, postgreSQL, and Sqlite. 默认情况下,它使用的驱动程序是:mysql,postgreSQL和Sqlite。

Eloquent itself can be downloaded without Laravel being involved. 雄辩的本身可以下载,无需Laravel参与。

Please refer to Jeffrey Way's Laracast for instruction: https://laracasts.com/lessons/how-to-use-eloquent-outside-of-laravel 请参考Jeffrey Way的Laracast以获得指示: https ://laracasts.com/lessons/how-to-use-eloquent-outside-of-laravel

...thanks all, ended up writting my own magic class: ...谢谢所有人,最后写了我自己的魔术课:

DBIntrd - Simple PHP framework for SQLite3 databases DBIntrd-用于SQLite3数据库的简单PHP框架

Tired of spending time writting a bunch of code to create PHP classes & methods for SQLite tables? 厌倦了花时间编写一堆代码来为SQLite表创建PHP类和方法?

DBIntrd is magic way to dinamically instance objects and persists data at SQLite3 tables.. DBIntrd是一种神奇的方法,可以动态地实例化对象并将数据持久化在SQLite3表中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM