抽象数据库类 [英] Abstracting a database class
问题描述
嘿所有!
我已经使用PHP一段时间了,我听说我应该调查
使用它OO 。我正在考虑更改相机生活计划
( http ://fdcl.sf.net)。我想抽象连接到数据库
当前是MYSQL并且可能实现另一个数据库,或者只是
让它打开以便添加。如果我很幸运并掌握了这一点,
我也想抽取对GD的电话。
首先,是否有一个好的解决这个问题?我见过很多
的例子,但其中很多都不完整或只是学术性的。另外,
我会通过这种方式失去任何功能吗?我目前使用带有CONCAT的复杂SELECT语句
。对于抽象的课程,这可能是
吗?
感谢您的考虑,
FD
>
Hey all!
I''ve been using PHP for a while and I''m hearing that I should look into
using it OO. I''m looking into making changes to the program Camera Life
(http://fdcl.sf.net). I want to abstract the connection to the database
which is currently MYSQL and maybe implement another database, or just
leave it open for addition. If I get lucky and get the hang of this,
I''d also like to abstract calls to GD.
So firstly, is there a good solution to this problem? I''ve seen many
examples, but many of them are incomplete or simply academic. Also,
will I lose any functionality by doing it this way? I am currently
using a complicated SELECT statement with a CONCAT. Will this be
possible with the abstracted class?
Thanks for your consideration,
FD
推荐答案
看看这个: http://adodb.sourceforge.net/ 抽象已经为你完成了
。或者,你可以在pear.php.net上查看他们的数据库课程
。
Balazs
Full Decent ; <福******** @ gmail.com>在消息中写道
news:11 ********************** @ o13g2000cwo.googlegr oups.com ...
Have a look at this: http://adodb.sourceforge.net/ The abstraction is
already done for you. Or, you can look on pear.php.net for their DB class
too.
Balazs
"Full Decent" <fu********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
嘿所有!
我已经使用PHP了一段时间,我听说我应该调查使用它OO。我正在考虑对相机生活计划进行更改
( http:// fdcl .sf.net)。我想抽象连接到数据库
当前是MYSQL并且可能实现另一个数据库,或者只是将它打开以便添加。如果我很幸运并掌握了这一点,那么我也想抽取对GD的电话。
首先,这个问题有一个很好的解决方案吗?我看过很多例子,但其中很多都是不完整的或只是学术性的。另外,这样做会失去任何功能吗?我目前正在使用带有CONCAT的复杂SELECT语句。对于抽象的课程,这是否可行?
感谢您的考虑,
FD
Hey all!
I''ve been using PHP for a while and I''m hearing that I should look into
using it OO. I''m looking into making changes to the program Camera Life
(http://fdcl.sf.net). I want to abstract the connection to the database
which is currently MYSQL and maybe implement another database, or just
leave it open for addition. If I get lucky and get the hang of this,
I''d also like to abstract calls to GD.
So firstly, is there a good solution to this problem? I''ve seen many
examples, but many of them are incomplete or simply academic. Also,
will I lose any functionality by doing it this way? I am currently
using a complicated SELECT statement with a CONCAT. Will this be
possible with the abstracted class?
Thanks for your consideration,
FD
Full Decent写道:
Full Decent wrote:
我已经使用PHP了一段时间,我听说我应该看看使用它OO。我正在考虑对程序进行更改
相机寿命( http:// fdcl .sf.net)。我想将连接抽象到当前MYSQL的数据库,并且可能实现另一个数据库,或者只是将其打开以进行添加。如果我很幸运并得到了这个问题,我也想抽取对GD的电话。
I''ve been using PHP for a while and I''m hearing that I should look
into using it OO. I''m looking into making changes to the program
Camera Life (http://fdcl.sf.net). I want to abstract the connection
to the database which is currently MYSQL and maybe implement another
database, or just leave it open for addition. If I get lucky and get
the hang of this, I''d also like to abstract calls to GD.
你可能想偷看如下:
http://www.php.net / dbx /
或者PHP5:
http://www.php.net/pdo/
JW
You might want to take a peek at the following:
http://www.php.net/dbx/
Or for PHP5:
http://www.php.net/pdo/
JW
Full Decent写道:
Full Decent wrote:
嘿所有!
我已经使用PHP一段时间了,我听说我应该调查
使用它OO。我正在考虑对相机生活计划进行更改
( http:// fdcl .sf.net)。我想抽象连接到数据库
当前是MYSQL并且可能实现另一个数据库,或者只是将它打开以便添加。如果我很幸运并掌握了这一点,那么我也想抽取对GD的电话。
首先,这个问题有一个很好的解决方案吗?我看过很多例子,但其中很多都是不完整的或只是学术性的。另外,这样做会失去任何功能吗?我目前正在使用带有CONCAT的复杂SELECT语句。这对抽象类来说是否可行?
感谢您的考虑,
FD
Hey all!
I''ve been using PHP for a while and I''m hearing that I should look into
using it OO. I''m looking into making changes to the program Camera Life
(http://fdcl.sf.net). I want to abstract the connection to the database
which is currently MYSQL and maybe implement another database, or just
leave it open for addition. If I get lucky and get the hang of this,
I''d also like to abstract calls to GD.
So firstly, is there a good solution to this problem? I''ve seen many
examples, but many of them are incomplete or simply academic. Also,
will I lose any functionality by doing it this way? I am currently
using a complicated SELECT statement with a CONCAT. Will this be
possible with the abstracted class?
Thanks for your consideration,
FD
我通常用双抽象。
第一个是数据库工厂,提供诸如SQL查询
支持,数据库连接共享,错误处理等概念。
第二个是数据库接口实现,它将一个类中的所有
SQL隔离开来。这个实现是
实例化工厂并使用它的唯一类。
这样,我可以更改数据库工厂(连接到不同的
数据库)轻松实现,由于接口实现包含所有SQL的b $ b,我只需要扫描一个文件来调整
差异在SQL语言中。 (例如,MySQL中的限制为1,而计数= 1,则为
Oracle)
抽象数据库通信(使用工厂)和
抽象接口是个好主意吗?我当然这么认为。事实上,
抽象所有通信在我的书中是个好主意。我也把它用于
我的所有SOAP工作。
-david-
I usually implement this with a double abstraction.
The first is a database factory to provide concepts such as SQL query
support, database connection sharing, error handling, etc.
The second is a database interface implementation that isolates all the
SQL in one class. This implementation is the only class that
instantiates the factory and uses it.
This way, I can change database factories (to connect to different
databases) with ease and, since the interface implementation contains
all the SQL, there is only one file I need to scan to adjust for the
variances in the SQL languages. (e.g. limit 1 in MySQL vs. count = 1 in
Oracle)
Is abstracting the database communications (with a factory) and
abstracting the interfaces a good idea? I certainly think so. In fact,
abstracting all communications is a good idea in my book. I use it for
all my SOAP work too.
-david-
这篇关于抽象数据库类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!