When accessing a MySQL-database from PHP there seems to be several ways:
当从PHP访问sql -database时,似乎有几种方法:
Sprinkle the code with raw SQL-statements
Use the VO-pattern from Java (e.g. DB_DataObjects from PEAR)
DIY and write a script that auto-generates one PHP class per database
Apart from this I have also read about LINQ in .NET
but have not seen it implemented in PHP.
What other patterns are there?
除此之外,我还在。net中阅读了关于LINQ的文章,但是还没有看到它在PHP中实现。还有其他的模式吗?
If you started building a website from scratch today, which one would you choose?
如果你今天开始从零开始建立一个网站,你会选择哪个?
Clarification: This is not about DB abstraction layers (PDO, MDB2). The pattern discussed here is something you build upon PDO or MDB2.
澄清:这与DB抽象层(PDO, MDB2)无关。这里讨论的模式是您在PDO或MDB2上构建的。
15 个解决方案
#1
5
I'd choose the MDB2 database abstraction layer from PEAR - it provides a nice, abstracted method to deal with the database. I recommend it, since it allows you to write portable code which can be ported to a different database server without many changes required (for a basic script, just changing the connect call is likely to be sufficient). It is a merge of the old DB and Metabase abstraction layers (DB is still supported for bugfixes, but has been superceded by MDB2).
我将从PEAR中选择MDB2数据库抽象层——它提供了一个很好的、抽象的方法来处理数据库。我推荐它,因为它允许您编写可移植的代码,这些代码可以移植到不同的数据库服务器,而不需要做很多修改(对于一个基本的脚本来说,仅仅修改连接调用就足够了)。它是旧的DB和Metabase抽象层的合并(DB仍然支持错误修复,但是已经被MDB2取代)。
It offers features like prepare + execute emulation for DBs that don't support it properly, and allows you to use placeholders which is good practice to avoid SQL injection problems.
它为DBs提供了准备+执行仿真等特性,这些特性不能正确地支持它,并且允许您使用占位符,这是避免SQL注入问题的良好实践。
It will work with: mysql / mysqli, pgsql (PostgreSQL), oci8 (Oracle), sqllite, msql, mssql (Microsoft SQL Server), sybase, informix, fbsql, ibase, odbc.
它将使用:mysql / mysqli、pgsql (PostgreSQL)、oci8 (Oracle)、sqllite、msql、mssql (Microsoft SQL Server)、sybase、informix、fbsql、ibase、odbc。
Have a look at the MDB2 documentation to see how it works.
请看MDB2文档,看看它是如何工作的。
#2
6
What you're looking for is an Object-Relational Model (ORM). There's a couple different ones out there:
您正在寻找的是对象关系模型(ORM)。有几个不同的例子:
If an ORM is too much for your project, then you would just fall back to a generic DB interface like PDO and build prepared statements manually.
如果ORM对于您的项目来说太大了,那么您就会退回到像PDO这样的通用数据库接口,并手工构建准备好的语句。
#3
2
What other patterns are there?
还有其他的模式吗?
ActiveRecord -- you can see an example of this in CakePHP.
ActiveRecord——您可以在CakePHP中看到这个示例。
I think it highly depends on your needs - if you're building a small application, it's probably quicker to build a DIY database layer.
我认为这很大程度上取决于您的需求——如果您正在构建一个小型应用程序,那么构建一个DIY数据库层可能会更快。
If you're building a big application with lots of tables and relationships, using something like CakePHP's ActiveRecord functionality will probably be quicker and easier.
如果您正在构建一个拥有大量表和关系的大型应用程序,那么使用CakePHP的ActiveRecord功能可能会更快、更简单。
I haven't used PEAR's abstraction layer yet but it also looks good. Zend also have a Database library in the Zend framework.
我还没有使用过PEAR的抽象层,但它看起来也不错。Zend框架中还有一个数据库库。
#4
1
"It depends"
“看情况”
For my own projects, I tend to use a framework of some sort, which includes an abstraction layer. For smaller projects that aren't appropriate for a framewok, I just put the SQL right in the script (because it's small). The last time I did a sizeable application without a framework, I used PDO for it's easy prepared statement support, etc. It's a pretty easy-to-learn abstraction layer. I'd probably use it again, if I chose not to use a framework for some reason.
对于我自己的项目,我倾向于使用某种框架,其中包括一个抽象层。对于不适合framewok的较小项目,我将SQL放在脚本中(因为它很小)。上次我在没有框架的情况下开发了一个相当大的应用程序时,我使用了PDO,因为它支持易于准备的语句等等。如果我选择不使用框架,我可能会再次使用它。
#5
1
Apart from this I have also read about LINQ in .NET but have not seen it implemented in PHP.
除此之外,我还在。net中阅读了关于LINQ的文章,但是还没有看到它在PHP中实现。
Something like Linq can't yet be implemented in PHP because the language lacks the necessary constructs. A kind of "fake linq" has been created, but this just uses strings and is not "real" linq. And even if it were, it is effectively just the equivilent of Linq to objects and there is nothing out there like Linq to SQL.
像Linq这样的东西还不能在PHP中实现,因为这种语言缺乏必要的结构。已经创建了一种“伪linq”,但它只是使用字符串,而不是“真正的”linq。即使它是,它实际上也只是Linq到对象的等价物,没有什么比Linq到SQL更好的了。
#6
1
If you want an object-oriented approach, here's what my approach has been recently.
如果您想要面向对象的方法,下面是我最近的方法。
I seperate things out into two classes,
我把东西分成两类,
First, a DatabaseTable class - takes a table name, a string that is that table's key. Secondly, I create a DatabaseObject class that represents a row in a DatabaseTable. The DatabaseObject has two routines setFromRow and getAsRow. SetFromRow will setup the object from an associative array of col=>value pairs, and get as row will essentially serialize the object as col=>value pairs.
首先,一个DatabaseTable类——接受一个表名,这个字符串是该表的键。其次,我创建了一个DatabaseObject类,它表示DatabaseTable中的一行。DatabaseObject有两个例程setFromRow和getAsRow。SetFromRow将从col=>值对的关联数组中设置对象,get as row将把对象序列化为col=>值对。
The DatabaseTable uses setFromRow to manufacture DatabaseObjects when the select method is called on the table. Conversely, when it is told to update or insert data into its table, the DatabsaeTable will serialize the DatabaseObject using getAsRow.
当在表上调用select方法时,DatabaseTable使用setFromRow来生成databaseobject。相反,当被告知要更新或将数据插入表时,DatabsaeTable将使用getAsRow对DatabaseObject进行序列化。
Typically what happens is one inherits from DatabaseObject for their own particular object, defines setFromRow and getAsRow, and the DatabaseTable is told the name of the DatabaseObject to instantiate.
通常发生的情况是,一个人从DatabaseObject继承自己的特定对象,定义setFromRow和getAsRow,并告诉DatabaseTable要实例化的DatabaseTable对象的名称。
So what you end up writing, code wise is something like this
所以你最后写的代码是这样的
$dbTable = new DatabaseTable('tableName', 'uniqueid', 'InstanceType')
// dbTable manufactures an InstanceType for our use based on the select below
$dbRow = $dbTable->selectUsingId(15);
print_r($dbRow); // Dumps the InstanceTypeObject
This separates the representation of data (DatabaseObject) in my application from the management of the database tables (DatabaseTable). So my DatabaseObject can be, in C++ terminology, plain-old-data.
这将我的应用程序中的数据表示(DatabaseObject)与数据库表的管理(DatabaseTable)分离开来。所以我的DatabaseObject可以,用c++术语来说,是纯旧数据。
Of course you can go even further, as I have, by creating relationships between tables, and creating more ways to select, etc.
当然,您可以像我一样更进一步,通过创建表之间的关系,以及创建更多的选择方法等等。
I should add that integrating what is essentially a procedural language (SQL) with what object-orientedness is not easy, so my method, I know, has its drawbacks and you are likely to get a lot of different answers each with their own drawbacks.
我应该补充一点,将本质上是一种过程语言(SQL)与面向对象集成起来并不容易,所以我的方法,我知道,有它的缺点,您可能会得到许多不同的答案,每个答案都有各自的缺点。
#7
1
You may also want to consider using CodeIgniter, a nice little MVC framework for PHP. It has both an ActiveRecord implementation and a reasonable set of Database objects (including bound variables). I find its DB classes much nicer than the default PHP MySQL APIs, and a bit simpler than PDOs (certainly easier to install).
您可能还想考虑使用CodeIgniter,这是一个很好的PHP MVC框架。它有一个ActiveRecord实现和一组合理的数据库对象(包括绑定变量)。我发现它的DB类比默认的PHP MySQL api好得多,比PDOs简单得多(当然安装起来也更容易)。
#8
#9
0
At the very least, use PDO. It provides a common interface to most database platforms, making it easier to switch database solutions, should you ever wish to.
至少,使用PDO。它为大多数数据库平台提供了通用的接口,使您可以更容易地切换数据库解决方案。
I like to use an Object Relational Mapper (ORM), like propel: http://propel.phpdb.org/trac/
我喜欢使用对象关系映射器(ORM),比如push: http://propel.phpdb.org/trac/。
This maps your objects straight to the database schema - no SQL required. Mapping happens in an XML file, Querying happens through Criteria objects. It's possible to reverse engineer PHP classes from a database, or generate a database from the schema xml.
这将直接将对象映射到数据库模式——不需要SQL。映射发生在XML文件中,查询发生在Criteria对象中。可以从数据库反向设计PHP类,也可以从模式xml生成数据库。
For more information about ORM in general, see http://en.wikipedia.org/wiki/Object-relational_mapping
有关ORM的更多信息,请参见http://en.wikipedia.org/wiki/Object-relational_mapping
#10
0
For executing a command, I'd use functions for commonly executed SQL commands. These functions can then be used to make something more specific like get_users()
对于执行一个命令,我将使用通常执行的SQL命令的函数。然后可以使用这些函数使get_users()更具体
a) Make a function for each of the queries you might want to make, such as
a)为您可能要进行的每个查询创建一个函数,例如
db_select($opts)
where $opts is a hash array with keys:
其中$opts是一个带有键的散列数组:
['table_name', 'selection', 'condition', 'group_by', 'order_by', 'limit']
b) If you used SQL heavily, I might be tempted to make a SQL command builder, which takes a hash array and returns a command. Something like:
b)如果您大量使用SQL,我可能会尝试创建一个SQL命令构建器,它接受一个散列数组并返回一个命令。喜欢的东西:
db_builder(array('select'=>array('customers','from'=>'bar','where'=>'foo=10')))
The above mentioned functions would use this in their implementations and so would you if you need a completely random statement, and hopefully the whole thing would be rock solid by reusing the command builder code everywhere.
上面提到的函数将在它们的实现中使用它,如果您需要一个完全随机的语句,并且希望通过在所有地方重用命令构建器代码,整个东西都是坚固的。
#11
0
Use an MVC structure and a database abstraction layer. This way you can go to one place to completely rework the internals of a data access class whilst keeping the public interface constant.
使用MVC结构和数据库抽象层。通过这种方式,您可以到一个地方,在保持公共接口不变的同时,完全重写数据访问类的内部结构。
Raw SQL throughout the code is going to be nigh on impossible to scale.
整个代码中的原始SQL几乎不可能扩展。
#12
0
I do a two-level handcoded approach:
我采用两级手工编码的方法:
first level is a simple set of functions:
第一级是一组简单的函数:
- do_query(sql): returns the (open) result object.
- do_query(sql):返回(打开的)结果对象。
- get_record(sql): returns the first record, the query is closed.
- get_record(sql):返回第一个记录,查询被关闭。
- get_datum(sql): returns the first field of the first record (query closed)
- get_datum(sql):返回第一个记录的第一个字段(查询关闭)
after that, i write my model layer, with specific functions for all data operations. usually a single file with sections for each conceptual object. the parameters are tied to the abstract data, not to the SQL structure. all SQL is in this layer.
在此之后,我将编写模型层,为所有数据操作提供特定的函数。通常是一个文件,每个概念性对象都有部分。参数绑定到抽象数据,而不是SQL结构。所有SQL都在这个层中。
#13
0
Read what Mr. Lerdorf himself has to say about "Adding Structure" to a PHP site.
阅读Mr. Lerdorf对PHP站点“添加结构”的看法。
www.oracle.com/technology/pub/articles/php_experts/rasmus_php.html
www.oracle.com/technology/pub/articles/php_experts/rasmus_php.html
#14
0
You could use an ORM like Doctrine .
你可以使用兽人的教义。
#15
0
Any way is good, as long as you minimize the points where you need to alter your code when your database schema changes (input, filtering, validation, form generation etc.).
任何方法都是好的,只要您最小化数据库模式更改时需要修改代码的点(输入、过滤、验证、表单生成等)。
I like to keep it simple with PDO, parametrized SQL and classes that abstract the data set returned (::getActiveUsers()
, ::getUserPersonalData()
etc.).
我喜欢使用PDO、参数化的SQL和抽象返回的数据集(::getActiveUsers()、::getUserPersonalData()等)的类保持简单。
#1
5
I'd choose the MDB2 database abstraction layer from PEAR - it provides a nice, abstracted method to deal with the database. I recommend it, since it allows you to write portable code which can be ported to a different database server without many changes required (for a basic script, just changing the connect call is likely to be sufficient). It is a merge of the old DB and Metabase abstraction layers (DB is still supported for bugfixes, but has been superceded by MDB2).
我将从PEAR中选择MDB2数据库抽象层——它提供了一个很好的、抽象的方法来处理数据库。我推荐它,因为它允许您编写可移植的代码,这些代码可以移植到不同的数据库服务器,而不需要做很多修改(对于一个基本的脚本来说,仅仅修改连接调用就足够了)。它是旧的DB和Metabase抽象层的合并(DB仍然支持错误修复,但是已经被MDB2取代)。
It offers features like prepare + execute emulation for DBs that don't support it properly, and allows you to use placeholders which is good practice to avoid SQL injection problems.
它为DBs提供了准备+执行仿真等特性,这些特性不能正确地支持它,并且允许您使用占位符,这是避免SQL注入问题的良好实践。
It will work with: mysql / mysqli, pgsql (PostgreSQL), oci8 (Oracle), sqllite, msql, mssql (Microsoft SQL Server), sybase, informix, fbsql, ibase, odbc.
它将使用:mysql / mysqli、pgsql (PostgreSQL)、oci8 (Oracle)、sqllite、msql、mssql (Microsoft SQL Server)、sybase、informix、fbsql、ibase、odbc。
Have a look at the MDB2 documentation to see how it works.
请看MDB2文档,看看它是如何工作的。
#2
6
What you're looking for is an Object-Relational Model (ORM). There's a couple different ones out there:
您正在寻找的是对象关系模型(ORM)。有几个不同的例子:
If an ORM is too much for your project, then you would just fall back to a generic DB interface like PDO and build prepared statements manually.
如果ORM对于您的项目来说太大了,那么您就会退回到像PDO这样的通用数据库接口,并手工构建准备好的语句。
#3
2
What other patterns are there?
还有其他的模式吗?
ActiveRecord -- you can see an example of this in CakePHP.
ActiveRecord——您可以在CakePHP中看到这个示例。
I think it highly depends on your needs - if you're building a small application, it's probably quicker to build a DIY database layer.
我认为这很大程度上取决于您的需求——如果您正在构建一个小型应用程序,那么构建一个DIY数据库层可能会更快。
If you're building a big application with lots of tables and relationships, using something like CakePHP's ActiveRecord functionality will probably be quicker and easier.
如果您正在构建一个拥有大量表和关系的大型应用程序,那么使用CakePHP的ActiveRecord功能可能会更快、更简单。
I haven't used PEAR's abstraction layer yet but it also looks good. Zend also have a Database library in the Zend framework.
我还没有使用过PEAR的抽象层,但它看起来也不错。Zend框架中还有一个数据库库。
#4
1
"It depends"
“看情况”
For my own projects, I tend to use a framework of some sort, which includes an abstraction layer. For smaller projects that aren't appropriate for a framewok, I just put the SQL right in the script (because it's small). The last time I did a sizeable application without a framework, I used PDO for it's easy prepared statement support, etc. It's a pretty easy-to-learn abstraction layer. I'd probably use it again, if I chose not to use a framework for some reason.
对于我自己的项目,我倾向于使用某种框架,其中包括一个抽象层。对于不适合framewok的较小项目,我将SQL放在脚本中(因为它很小)。上次我在没有框架的情况下开发了一个相当大的应用程序时,我使用了PDO,因为它支持易于准备的语句等等。如果我选择不使用框架,我可能会再次使用它。
#5
1
Apart from this I have also read about LINQ in .NET but have not seen it implemented in PHP.
除此之外,我还在。net中阅读了关于LINQ的文章,但是还没有看到它在PHP中实现。
Something like Linq can't yet be implemented in PHP because the language lacks the necessary constructs. A kind of "fake linq" has been created, but this just uses strings and is not "real" linq. And even if it were, it is effectively just the equivilent of Linq to objects and there is nothing out there like Linq to SQL.
像Linq这样的东西还不能在PHP中实现,因为这种语言缺乏必要的结构。已经创建了一种“伪linq”,但它只是使用字符串,而不是“真正的”linq。即使它是,它实际上也只是Linq到对象的等价物,没有什么比Linq到SQL更好的了。
#6
1
If you want an object-oriented approach, here's what my approach has been recently.
如果您想要面向对象的方法,下面是我最近的方法。
I seperate things out into two classes,
我把东西分成两类,
First, a DatabaseTable class - takes a table name, a string that is that table's key. Secondly, I create a DatabaseObject class that represents a row in a DatabaseTable. The DatabaseObject has two routines setFromRow and getAsRow. SetFromRow will setup the object from an associative array of col=>value pairs, and get as row will essentially serialize the object as col=>value pairs.
首先,一个DatabaseTable类——接受一个表名,这个字符串是该表的键。其次,我创建了一个DatabaseObject类,它表示DatabaseTable中的一行。DatabaseObject有两个例程setFromRow和getAsRow。SetFromRow将从col=>值对的关联数组中设置对象,get as row将把对象序列化为col=>值对。
The DatabaseTable uses setFromRow to manufacture DatabaseObjects when the select method is called on the table. Conversely, when it is told to update or insert data into its table, the DatabsaeTable will serialize the DatabaseObject using getAsRow.
当在表上调用select方法时,DatabaseTable使用setFromRow来生成databaseobject。相反,当被告知要更新或将数据插入表时,DatabsaeTable将使用getAsRow对DatabaseObject进行序列化。
Typically what happens is one inherits from DatabaseObject for their own particular object, defines setFromRow and getAsRow, and the DatabaseTable is told the name of the DatabaseObject to instantiate.
通常发生的情况是,一个人从DatabaseObject继承自己的特定对象,定义setFromRow和getAsRow,并告诉DatabaseTable要实例化的DatabaseTable对象的名称。
So what you end up writing, code wise is something like this
所以你最后写的代码是这样的
$dbTable = new DatabaseTable('tableName', 'uniqueid', 'InstanceType')
// dbTable manufactures an InstanceType for our use based on the select below
$dbRow = $dbTable->selectUsingId(15);
print_r($dbRow); // Dumps the InstanceTypeObject
This separates the representation of data (DatabaseObject) in my application from the management of the database tables (DatabaseTable). So my DatabaseObject can be, in C++ terminology, plain-old-data.
这将我的应用程序中的数据表示(DatabaseObject)与数据库表的管理(DatabaseTable)分离开来。所以我的DatabaseObject可以,用c++术语来说,是纯旧数据。
Of course you can go even further, as I have, by creating relationships between tables, and creating more ways to select, etc.
当然,您可以像我一样更进一步,通过创建表之间的关系,以及创建更多的选择方法等等。
I should add that integrating what is essentially a procedural language (SQL) with what object-orientedness is not easy, so my method, I know, has its drawbacks and you are likely to get a lot of different answers each with their own drawbacks.
我应该补充一点,将本质上是一种过程语言(SQL)与面向对象集成起来并不容易,所以我的方法,我知道,有它的缺点,您可能会得到许多不同的答案,每个答案都有各自的缺点。
#7
1
You may also want to consider using CodeIgniter, a nice little MVC framework for PHP. It has both an ActiveRecord implementation and a reasonable set of Database objects (including bound variables). I find its DB classes much nicer than the default PHP MySQL APIs, and a bit simpler than PDOs (certainly easier to install).
您可能还想考虑使用CodeIgniter,这是一个很好的PHP MVC框架。它有一个ActiveRecord实现和一组合理的数据库对象(包括绑定变量)。我发现它的DB类比默认的PHP MySQL api好得多,比PDOs简单得多(当然安装起来也更容易)。
#8
1
It definitely will depend on how big of a web app you're writing. I'll add my thumbs-up for Doctrine (when used appropriately). If it's a farly small quick-n-dirty project, you could probably just get away with using PDO.
这肯定取决于你写的web应用程序有多大。我将为教义加上我的意见(如果使用得当)。如果这是一个非常小的快速-肮脏的项目,你可以使用PDO。
#9
0
At the very least, use PDO. It provides a common interface to most database platforms, making it easier to switch database solutions, should you ever wish to.
至少,使用PDO。它为大多数数据库平台提供了通用的接口,使您可以更容易地切换数据库解决方案。
I like to use an Object Relational Mapper (ORM), like propel: http://propel.phpdb.org/trac/
我喜欢使用对象关系映射器(ORM),比如push: http://propel.phpdb.org/trac/。
This maps your objects straight to the database schema - no SQL required. Mapping happens in an XML file, Querying happens through Criteria objects. It's possible to reverse engineer PHP classes from a database, or generate a database from the schema xml.
这将直接将对象映射到数据库模式——不需要SQL。映射发生在XML文件中,查询发生在Criteria对象中。可以从数据库反向设计PHP类,也可以从模式xml生成数据库。
For more information about ORM in general, see http://en.wikipedia.org/wiki/Object-relational_mapping
有关ORM的更多信息,请参见http://en.wikipedia.org/wiki/Object-relational_mapping
#10
0
For executing a command, I'd use functions for commonly executed SQL commands. These functions can then be used to make something more specific like get_users()
对于执行一个命令,我将使用通常执行的SQL命令的函数。然后可以使用这些函数使get_users()更具体
a) Make a function for each of the queries you might want to make, such as
a)为您可能要进行的每个查询创建一个函数,例如
db_select($opts)
where $opts is a hash array with keys:
其中$opts是一个带有键的散列数组:
['table_name', 'selection', 'condition', 'group_by', 'order_by', 'limit']
b) If you used SQL heavily, I might be tempted to make a SQL command builder, which takes a hash array and returns a command. Something like:
b)如果您大量使用SQL,我可能会尝试创建一个SQL命令构建器,它接受一个散列数组并返回一个命令。喜欢的东西:
db_builder(array('select'=>array('customers','from'=>'bar','where'=>'foo=10')))
The above mentioned functions would use this in their implementations and so would you if you need a completely random statement, and hopefully the whole thing would be rock solid by reusing the command builder code everywhere.
上面提到的函数将在它们的实现中使用它,如果您需要一个完全随机的语句,并且希望通过在所有地方重用命令构建器代码,整个东西都是坚固的。
#11
0
Use an MVC structure and a database abstraction layer. This way you can go to one place to completely rework the internals of a data access class whilst keeping the public interface constant.
使用MVC结构和数据库抽象层。通过这种方式,您可以到一个地方,在保持公共接口不变的同时,完全重写数据访问类的内部结构。
Raw SQL throughout the code is going to be nigh on impossible to scale.
整个代码中的原始SQL几乎不可能扩展。
#12
0
I do a two-level handcoded approach:
我采用两级手工编码的方法:
first level is a simple set of functions:
第一级是一组简单的函数:
- do_query(sql): returns the (open) result object.
- do_query(sql):返回(打开的)结果对象。
- get_record(sql): returns the first record, the query is closed.
- get_record(sql):返回第一个记录,查询被关闭。
- get_datum(sql): returns the first field of the first record (query closed)
- get_datum(sql):返回第一个记录的第一个字段(查询关闭)
after that, i write my model layer, with specific functions for all data operations. usually a single file with sections for each conceptual object. the parameters are tied to the abstract data, not to the SQL structure. all SQL is in this layer.
在此之后,我将编写模型层,为所有数据操作提供特定的函数。通常是一个文件,每个概念性对象都有部分。参数绑定到抽象数据,而不是SQL结构。所有SQL都在这个层中。
#13
0
Read what Mr. Lerdorf himself has to say about "Adding Structure" to a PHP site.
阅读Mr. Lerdorf对PHP站点“添加结构”的看法。
www.oracle.com/technology/pub/articles/php_experts/rasmus_php.html
www.oracle.com/technology/pub/articles/php_experts/rasmus_php.html
#14
0
You could use an ORM like Doctrine .
你可以使用兽人的教义。
#15
0
Any way is good, as long as you minimize the points where you need to alter your code when your database schema changes (input, filtering, validation, form generation etc.).
任何方法都是好的,只要您最小化数据库模式更改时需要修改代码的点(输入、过滤、验证、表单生成等)。
I like to keep it simple with PDO, parametrized SQL and classes that abstract the data set returned (::getActiveUsers()
, ::getUserPersonalData()
etc.).
我喜欢使用PDO、参数化的SQL和抽象返回的数据集(::getActiveUsers()、::getUserPersonalData()等)的类保持简单。