SuperTaoer::Thanksgiving

不要追求外表,她会骗人;不要追求财富,他会消失;追求一个让你微笑开颜的人吧,因为微笑会让你灰暗的一天豁然开朗,阳光明媚!!!

十月 17, 2005

ADOdb Lite how to/install 文档中文翻译 和 ADOdb Lite 使用小记

类归于: 程序 技术 — SuperTaoer @ 3:22 上午

[原创]转载请注明出处。
使用adodb lite很简单,抛弃臃肿的adodb,牺牲一些功能来换来一些效率。
这个小记算是adodb lite 的中文 How To Install & Connect吧。
这篇文章的英文原文地址是: adodblite.sourceforge.net/howtoinstall.php
或者这里: www.taoer.com/doc/mydocs/php/adodb_lite1.03
在网上没有搜到adodb lite 的中文文档,只好自己用半吊子英文翻译出来了。。。
省略去解压缩,包含文件啥的等步骤。。。。。。
——-连接到你的数据库
1.包含文件

  1. require_once "adodb.inc.php";

2.设定数据库类型,完整的数据库类型列表参考 这里

  1. $db = ADONewConnection("mysql");

3.设定是否自动创建数据库(意思是如果你链接的数据库不存在,则自动建立,这个意义不大,我设为false)

  1. $db->createdatabase = false;

4.设定是否显示调试信息(如果你希望每次数据库查询都显示错误信息,你可以设为true,默认是false)
PS:个人建议,调试程序设置为true,服务上线修改为false,可以把错误信息记录在log里面

  1. $db->debug = true;

5.建立数据库连接

  1. $result = $db->Connect("$dbhost", "$dbuname", "$dbpass", "$dbname");

或者建立持久连接

  1. $result = $db->PConnect("$dbhost", "$dbuname", "$dbpass", "$dbname");

或者强制建立新连接

  1. $result = $db->NConnect("$dbhost", "$dbuname", "$dbpass", "$dbname");

参数说明:
$dbhost: 数据库的地址,可以为url或者ip地址,例如:http://127.0.0.1 或者 www.yourhost.com 或者 localhost
$dbuname: 一个可以访问数据库的用户名
$dbpass: 一个和 $dbuname 匹配的可以访问数据库的密码
$dbname: 你要访问的数据库名
举例:

  1. require_once "adodb.inc.php";
  2. $db = ADONewConnection("mysql");
  3. $db->createdatabase = false;
  4. $result = $db->Connect("$dbhost", "$dbuname", "$dbpass", "$dbname");

——-可选的连接标识
1.Mysql/Mysqli/Mysqlt:
$db->port = 通过端口号进行连接。
$db->clientflags = 这个客户端参数可以是以下的几个常量:MYSQL_CLIENT_COMPRESS, MYSQL_CLIENT_IGNORE_SPACE or MYSQL_CLIENT_INTERACTIVE。(PHP 4.3.0或者更高版本)
Mysqli:
$db->socket = 指定socket或者指定pipe来使用
Postgres(all):
$db->port = 通过端口号进行连接。
——-DSN(Data Source Name)连接方法
如果你使用DSN连接字符串代替数据库类型,你可以选择你的数据库驱动并同时连接。DSN可以扩展使用锚标记来包含模块(可能翻译的不是很准确)。
You can perform your driver selection and connection all at the same time if you use a DSN connection string instead of the databasetype. The DSN entry has been expanded to use the anchor symbol for the inclusion of modules.
$driver://$username:$password@$hostname/$database?options[=value]#$modules
例如: $driver://$user_root:$pwd_root@$localhost/$test?options[=value]#$modules
至于options和modules还没有提到,先不作解释。
$driver = 在上面告诉你的数据库类型列表中选择你的数据库类型并用找到的字符串来定义这个变量
$username = 可以访问你的数据库的用户名
$password = 访问你数据库用户名相对应的密码
$hostname = 数据库的地址,可以为url或者ip地址,例如:http://127.0.0.1 或者 www.yourhost.com 或者 localhost
$database = 你要访问的数据库名
$options = 所用的驱动 - ‘持续’,'持续稳固的’, ‘调试’, ‘取得数据集模式:’
Mysql(all) - ‘端口’, ‘客户端标识’
Mysqli - ’socket’
Postgress(all) - ‘端口’
PS:翻译的不是很准确,把英文放在后面作为对照
$options = All Drivers - ‘persist’, ‘persistent’, ‘debug’, ‘fetchmode’
Mysql (all) - ‘port’, ‘clientflags’
Mysqli - ’socket’
Postgress (all) - ‘port’
$modules = 模块可以加载。例如,PEAR,cache,extend,etc…
PS:翻译的不是很准确,把英文放在后面作为对照
$modules = The modules that should be loaded. IE: pear, cache, extend, ect..
你可以仅使用单一的命令来选择你的驱动并且连接数据库代替两行的命令字符串

  1. require_once "adodb.inc.php";
  2. $flags = MYSQL_CLIENT_COMPRESS;
  3. $dsn_string = 'mysql://user:junk@localhost/mydb?persist&clientflags=$flags#pear:extend';
  4. $db = ADONewConnection($dsn_string);

上面的例子使用mysql的数据库驱动创建一个持久的mysql数据库连接。用户名识user,密码识junk,主机地址是localhost,并且启动mysql的压缩选项,加载pear和extend模块。
——-ADODB Lite 配置文件
ADODB Lite 使用一个配置文件(adodb.config.php)来提供比ADOdb更好的应用。当通过配置文件连接数据库你可以指定你需要加载的模块。
例如:

  1. < ?
  2. /**
  3. * ADOdb Lite Configuration File
  4. */
  5. /**
  6. * Set the $dbtype variable to the database designator.
  7. * If this variable is enabled it will override the database designator
  8. * entered in the ADONewConnection( $dbtype ) function. The database
  9. * designator in a DSN string will be overridden but the rest of the DSN
  10. * string will be used.
  11. *
  12. * You can place a DSN entry in the $dbtype variable if you would like to
  13. * auto connect to your database.
  14. *
  15. * Example:
  16. *
  17. * $dbtype = "driver://username:password@hostname/database?options[=value]#modules";
  18. *
  19. * driver = Databasetype Designator listed in the table at the start of this page.
  20. * username = The Username needed to access the database
  21. * password = Optional password for accessing the database
  22. * hostname = localhost or url/ip address IE: http://0.0.0.0 or http://www.dbserver.com 
  23. * database = The name of the database you will be accessing
  24. * options = All Drivers - 'persist', 'persistent', 'debug', 'fetchmode'
  25. * Mysql (all) - 'port', 'clientflags'
  26. * Mysqli - 'socket'
  27. * Postgress (all) - 'port'
  28. * modules = The modules that should be loaded. IE: pear, cache, extend, ect.
  29. *
  30. */
  31. // $dbtype = "mysql";
  32. /**
  33. * If you want to maintain compatability with the ADOdb ADONewConnection( $dbtype )
  34. * function you should designate the modules you need loaded below. If you designate
  35. * the modules below you do not need to designate them in
  36. * ADONewConnection( $dbtype, $modules ).
  37. *
  38. * If you would like more than one module loaded at the same time concatinate the
  39. * module names using a colon (:).
  40. *
  41. * Example:
  42. * $modules = "pear:transaction:extend";
  43. *
  44. * The above example would load the Pear, Transaction and Extend modules
  45. * automatically.
  46. */
  47. $modules = "pear:extend";
  48. ?>

上面的这个例子都能看懂吧,就不用翻译了,呵呵。
在上面这个例子自动的加载了Pear和Extend模块 当

  1. $db = ADONewConnection( $dbtype );

这行语句被执行的时候。
由于改变了上面的配置文件,你就不需要这么来连接数据库了

  1. $db = ADONewConnection( $dbtype, 'pear:extend');

这样维护100%的兼容当前使用的ADOdb应用并且更容易的更换到ADOdb Lite。
This maintains 100% compatability for applications currently using ADOdb and makes it easier for them to change to ADOdb Lite.
我推荐使用这个配置文件来让ADOdb Lite知道都有什么模块需要被代替到DSN的tag或者添加模块到ADONewConnection的函数中。这样允许你现有的应用来使用ADOdb Lite。
I recommend using this configuration file for telling ADOdb Lite what modules should be used instead of using the DSN anchor tag or adding the modules to the ADONewCOnnection function. This will allow you to use ADOdb Lite with existing applications.
PS:上面的两句翻译的不是很准确,但是大致意思应该对了,把英文的原文放在下面供大家参考。
——-ADOdb 模块
从这里我将要用modules100%的兼容ADOdb。我可以添加一个模块系统到包里面,允许你选择模块如果你愿意加载的话。我们将提供两个模块 release的Transaction 和 Pear。
The one departure I am going to make from 100% compatibility with ADOdb is with modules. I have added a module system to the package that will allow you to select the modules you would like to have loaded. We will be offering two modules with this release for Transaction and Pear.
你可以使用第二个命令(参数)当你设立你的ADOdb Lite的时候。
There is a second command you can use when setting up your ADOdb Lite.

  1. $db = ADONewConnection($databasetype, $module);

$module变量是可选的
PS:上面的两句翻译的不是很准确,但是大致意思应该对了,把英文的原文放在下面供大家参考。
例子:

  1. $db = ADONewConnection('postgres7', 'transaction');

上面使用 Postgres 7 数据库加载了 Transaction 模块。
下一个模块将是Pear。
例子:

  1. $db = ADONewConnection('postgres7', 'pear');

如果你需要同时两个模块都加载

  1. $db = ADONewConnection('postgres7', 'transaction : pear');

如果你需要加载多个模块你可以想这样输入多个你想要的。他们中间用冒号(:)来分隔每个模块在你的列表。
If you need to load multiple modules you can enter as many as you want. You will need to place a colon (:) between each module in your list.
例子:

  1. require_once "adodb.inc.php";
  2. $db = ADONewConnection('databasetype', 'pear : transaction : cache' );
  3. $db->createdatabase = true ;
  4. $result = $db->Connect("$dbhost", "$dbuname", "$dbpass", "$dbname");

上面的这个例子加载了 Pear,Transaction 和 Cache 这3个模块。 他们允许你是用命令/函数来访问这些模块。他们不限制有多少模块被加载。
The above example would load the Pear, Transaction and Cache modules. This would allow you to use the commands/functions associated with those modules. There isn’t a limit to how many modules that may be loaded.
我没有一个固定的日期 为 当 数据库缓存 将要出现 因为我没有一个固定的路标 我将继续扩展数据库缓存部分的代码。我有一个想法,不过我需要先试验一下。
I do not have a firm date for when database caching will be coming out because I do not have a firm roadmap on how I will impliment the code for database caching. I have a number of ideas that I need to try out first.
PS:这段翻译的最烂了,希望明白的朋友留言给我,thanks :)
——-结尾
如果你使用ADODB你会注意到ADOdb Lite 是标准的使用ADODB的参数和命令。这样做可以让你的多个站点非常容易的转换到ADOdb Lite。
If you are familier with ADODB you will notice ADOdb Lite is started using the same parameters and commands. This makes it very easy for many sites to transfer over to ADOdb Lite.
感谢你把这篇文章读完,如果对你有所帮助我非常荣幸,翻译的不是很准确,有什么错误欢迎提出来,我会及时修正的。



Leave a Message

No Messages

No Messages

RSS feed for comments on this post. TrackBack URI

Leave a Message





Powered by WordPress