![mdb 转db](https://img-blog.csdnimg.cn/img_convert/7737c885d7c8bdf15df067e517c8c160.png)
mdb 转db
介绍(Intro)
Recently I had to move an existing project from using PEAR::DB to PEAR::MDB2 - the new database abstraction layer. I took notes on the parts of the code I needed to change, I hope they can benefit someone who's doing the same. Many thanks go to Lukas Smith, the lead developer, he was always responding very fast to my reports and questions in the PEAR mailing list.
最近,我不得不将现有项目从使用PEAR :: DB迁移到PEAR :: MDB2-新的数据库抽象层。 我记下了需要更改的代码部分,希望它们可以使这样做的人受益。 非常感谢首席开发人员Lukas Smith ,他一直对PEAR邮件列表中的报告和问题做出非常快速的响应。
One thing to notice in MDB2 is that it tries not to do any unnecessary work and does many things only on demand. For example when you create an object, that doesn't mean that a connection is established. It is established only when you make the first real database access, a SELECT
for example.
在MDB2中要注意的一件事是,它试图不做任何不必要的工作,并且仅在需要时才做很多事情。 例如,当您创建对象时,这并不意味着已建立连接。 仅当您首次进行真正的数据库访问(例如SELECT
时,才会建立该数据库。
I assume you have an idea of PEAR::DB, since this posting illustrates a DB-to-MDB2 endeavour, but even if you don't, I hope the posting will still be useful as an intro to DB and MDB2.
我假设您有一个PEAR :: DB的想法,因为此发布说明了从DB到MDB2的工作,但是即使您没有,我希望该发布对DB和MDB2的介绍还是有用的。
包括库 (Including the libs)
So first off, including the libs (I assume you have PEAR on your machine).
所以首先,包括库(我假设您的计算机上装有PEAR)。
require_once 'DB.php';
require_once 'MDB2.php';
One thing to note here is that installing MDB2 doesn't install any of the database wrappers. So if you use MySQL for example, you'd need to install it separately: pear install MDB2_Driver_mysql-beta
in addition to pear install MDB2-beta
这里要注意的一件事是,安装MDB2不会安装任何数据库包装程序。 因此,例如,如果您使用MySQL,则需要单独安装它:除pear install MDB2-beta
外, pear install MDB2-beta
pear install MDB2_Driver_my