| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> php >> shi yong PHPLIB fang wen duo ge shu ju ku

shi yong PHPLIB fang wen duo ge shu ju ku

2008-12-23 08:12:56 编辑來源:互联网 评论
 
 
 
本文为【使用PHPLIB访问多个数据库】的拼音翻译版
  PHPLIB shi PHP de yi xie kuo zhan ku , shi yong ta wo men ke yi hen fang bian di dui shu ju ku jin xing ge zhong cao zuo , bu guo , ru guo ni yao shi yong duo ge shu ju ku de hua , ta jiu xian de li bu cong xin le , ben wen jie shao le tong guo kuo zhan PHPLIB, rang ni yu he xiong zhang jian de , zai shi yong PHPLIB de tong shi ke yi shi yong duo ge shu ju ku , er qie cong zhong ni ye ke yi le jie dao mian xiang dui xiang bian cheng he ru he kuo zhan ku de zhi shi , zhi de yi du 。
  shu ju ku guan li
  ni ke yi zai yi ge da xing de shu ju ku zhong fang ru ren he biao 。 bu guo shi jian chang le , jiang hui ling shu ju ku bian de yue lai yue da , fu wu qi ke neng hui gen bu shang IO de gong zuo , huo zhe mei you zu gou de nei cun ying fu suo you de fang wen ? yao fen kai xian you de shu ju you fei chang nan 。 ming zhi de ban fa shi kai shi shi jiu shi yong fen kai de shu ju ku , bing qie jin xing you xiao de shu ju ku guan li 。 ru guo ni you yi ge mai shu de wang zhan , ni ke neng you zuo zhe de lie biao , shu jia de lie biao , huan you dang qian de ku cun he ding dan de lie biao 。 dang ni de ye wu bu duan zeng chang shi , ding dan jiang hui bu duan di zeng chang , er qie chu li mei ge ding dan dou xu yao jin xing hen duo de ci pan fang wen 。 hen ke neng ni jiang zai mou yi tian jiang suo you de ding dan dou fang dao yi ge hui ji xi tong zhong 。
  xian zai jiu jiang ding dan fang dao yi ge du li de shu ju ku ba 。 you yu ku cun ye shi tong guo ding dan geng xin de , yin ci ku cun liang ye fang dao tong yang de shu ju ku zhong 。
  zuo zhe de lie biao he shu de lie biao dou shi yi xie jing tai de xin xi , yao jing chang du qu , dan hen shao geng xin 。 shi ji shang , geng xin yi ge zuo zhe de ji lu ke neng zhi xu yao mei 5 nian yi ci , zhi zai zuo zhe xie le yi ben xin shu ( huo zhe qu shi ) shi jin xing 。 fang zhe xie shu ju de fu wu qi de pei zhi ke yu fang ding dan shu ju ku de fu wu qi wan quan bu tong 。
  bao han PHPLIB
  PHPLIB tong guo yi ge cheng wei DB_Sql de lei fang wen SQL shu ju ku 。 gen ju ni xu yao shi yong de shu ju ku lei xing , jiang bu tong de inc wen jian bao han zai ni de dai ma zhong 。 zai zhe ge li zi zhong , wo shi yong MySQL de ban ben 。
  wei le zai ni de dai ma zhong shi yong DB_Sql, yao jiang PHPLIB wen jian an zhuang zai ta men zi ji de mu lu zhong 。 ran hou , zhao dao ni de cgi-bin mu lu , bing qie zai cgi-bin de mu lu pang chuang jian phplib mu lu 。 xia yi bu , kao bei suo you de PHPLIB .inc wen jian dao phplib mu lu 。 zui hou , xiu gai php.inc wen jian , zhi yao jiang “include_path=” de xing gai wei gai phplib mu lu jiu ke yi le 。
  include_path shi PHP shi yong include() huo zhe require() shi cha zhao de mu lu , zai wo de NT workstation zhong ,include de lu jing shi :
  include_path = ".;i:/project52/includes;i:/project52/phplib";
  zai Linux de xi tong shang
  include_path = ".;/home/httpd/includes;/home/httpd/phplib";
  zai mei ge PHP ye mian de ding bu jia ru
  <?php
  require(common.php);
  ?>
  common.php3 fang zai includes mu lu zhong , bao han le mei ge ye mian yao yong dao de suo you shu ju he han shu 。 zai zhe ge li zi zhong de common.php shi :
  <?php
  require(db_mysql.inc);
  require(ct_sql.inc);
  require(session.inc);
  require(auth.inc);
  require(perm.inc);
  require(user.inc);
  require(page.inc);
  ?>
  ru guo ni xiang zhi dao mei ge inc wen jian de yong chu , ke yue du http://phplib.netuse.de shang de PHPLIB wen dang 。Db_mysql.inc bao han le suo you DB_SQL lei de ding yi 。 ru guo ni xiang shi yong PostGreSQL dai ti MySQL, zhi yao yong db_pgsql.inc dai ti db_mysql.inc jiu ke yi le 。 huan you 10 ge qi ta de .inc wen jian , ke yi shi yong MS SQL、Oracle、Sybase huo zhe qi ta de shu ju ku 。
  yao zhu yi de shi , zai zhe ge li zi zhong ,require() he include() shi wan quan yi yang de 。 bu guo , ru guo fang zai dai ma zhong , huo zhe zai if yu ju zhong shi yong shi ,Require() he include de shi yong shi wan quan bu tong de , bing qie you bu tong de yun xing jie guo 。
  kuo zhan PHPLIB
  PHPLIB tong guo yi ge DB_Sql lei chan sheng de dui xiang lai fang wen shu ju ku 。Db_mysql.inc bao han le wei MySQL xiu gai guo de DB_Sql lei 。 wo men jiang tong guo zai common.php zhong jia ru dai ma lai kuo zhan DB_sql, zhe xie dai ma jiang jia zai bao han db_mysql.inc de xing hou 。
  DB_Sql bao han le hen duo yong zuo cha xun de han shu , wo men yao zuo xiu gai de shi :
  <?php
  /* public: lian jie guan li */
  function connect($Database = "", $Host = "", $User = "", $Password = "") {
  /* chu li mo ren lian jie */
  if ("" == $Database)
  $Database = $this->Database;
  if ("" == $Host)
  $Host = $this->Host;
  if ("" == $User)
  $User = $this->User;
  if ("" == $Password)
  $Password = $this->Password;
  /* jian li lian jie , xuan ze shu ju ku */
  if ( 0 == $this->Link_ID ) {
  $this->Link_ID=mysql_pconnect($Host, $User, $Password);
  if (!$this->Link_ID) {
  $this->halt("pconnect($Host, $User, $Password) failed.");
  return 0;
  }
  if (Database,$this-]Link_ID"!@mysql_select_db($Database,$this->Link_ID)) {
  $this->halt("cannot use database ".$this->Database);
  return 0;
  }
  }
  return $this->Link_ID;
  }
  ?>
  zai ni de db_mysql.inc( huo zhe qi ta shu ju ku de xiang guan .inc wen jian ) zhong zhao dao connect() han shu , ran hou jiang ta kao bei dao common.php, fang dao bao han db_mysql.inc dai ma de hou mian , zai hou mian , huan yao jiang ta feng zhuang wei yi ge lei de ding yi 。
  wo fa xian zhe xie dai ma you xie nan du , yin ci , shou xian ling kao bei lai de dai ma de ke du xing geng hao :
  <?php
  /* public: lian jie guan li */
  function connect($Database = "", $Host = "", $User = "", $Password = "") {
  /* chu li mo ren lian jie */
  if ("" == $Database) {
  $Database = $this->Database;
  }
  if ("" == $Host) {
  $Host = $this->Host;
  }
  if ("" == $User) {
  $User = $this->User;
  }
  if ("" == $Password) {
  $Password = $this->Password;
  }
  /* jian li lian jie , xuan ze shu ju ku */
  if ( 0 == $this->Link_ID ) {
  $this->Link_ID=mysql_pconnect($Host, $User, $Password);
  if (!$this->Link_ID) {
  $this->halt("pconnect($Host, $User, $Password) failed.");
  return 0;
  }
  if (Database,$this-]Link_ID"!@mysql_select_db($Database,$this->Link_ID)) {
  $this->halt("cannot use database ".$this->Database);
  return 0;
  }
  }
  return $this->Link_ID;
  }
  ?>
  wo tiao zheng le yi xia kuo hao de wei zhi , bing qie zai dan xing de qian hou ye jia ru le yi ge da kuo hao 。 zai PHP de if yu ju zhong , ru guo zhi you yi ju dai ma de hua ni ke yi bu yong kuo hao , dan shi , ru guo ni zeng jia duo yi xing dai ma , jiu hui ma shang chu cuo 。 yin ci wo jian yi ni jia ru yi ge kuo hao , yi mian hou lai jia ru dai ma shi chu cuo 。
  zai gai bian connect de dai ma zhi qian , xian yao le jie yi xia connect() shi ru he gong zuo de , ta jian cha dang qian shi fou cun zai yi ge lian jie , ru guo bu cun zai lian jie de hua , jiu chuang jian yi ge lian jie 。 zai mei ci de shu ju ku cha xun zhi qian , shou xian yun xing zhe ge connect() han shu 。 ke xi de shi , ta zhi zai shou ci lian jie de shi hou xuan ze shu ju ku , ru guo ni de PHP ye mian shi yong chao guo yi ge shu ju ku ,connect() bing bu hui xuan ze ling wai de shu ju ku 。
  yao gai bian dai ma de hua , you ji zhong bu tong de fang fa 。 wo men yao xuan ze yi zhong dui PHPLIB de ying xiang zui xiao , er qie ke rang wo men zai xu yao fen xi wen ti de shi hou , neng gou xian shi shu ju ku lian jie zhuang tai de fang fa 。 wo men xu yao zai PHPLIB wai bao cun lian jie id he shu ju ku de ming zi 。 zhi yao zai common.php jia ru :
  <?php
  $db_connection = 0; // shu ju ku lian jie de id
  $db_database = ""; // dang qian shu ju ku de zhuang tai
  ?>
  xia yi bu , wo men yao dui PHPLIB zuo xiu gai , yi bian zai zhe xie bian liang zhong cun chu lian jie id he shu ju ku de ming zi 。 zai qi ta de dai ma zhong , ni ke yi she zhi he shi yong tong yang de bian liang ming 。 zai fen xi wen ti shi , ru guo ni xu yao zhi dao xian zai shi yong na ge shu ju ku , zhi yao zai ye mian zhong cha ru yi xia de dai ma :
  <?php
  Print(" db_database: " . $db_database . "");
  ?>
  wo men zen yang cai neng rang connect() shi yong zhe xie xin bian liang ne ? wo men ke yi zai ding bu jia ru yi xing :
  <?php
  {
  globals $db_connect, $db_database;
  /* Handle defaults */
  ?>
  tong guo zhe xie dai ma , xin bian liang jiu ke bei connect() fang wen dao
  zai ding yi le $db_database hou , jia ru :
  <?php
  function db_connect($db_connect_host="", $db_connect_user="",$db_connect_pass="") {
  globals $db_connect;
  if(!empty($db_connect_host)) {
  $db_connect = mysql_pconnect($db_connect_host,
  $db_connect_user, $db_connect_pass);
  }
  return($db_connect);
  }
  function db_database($db_database_new="") {
  globals $db_database;
  if(!empty($db_database_new)) {
  $db_database = @mysql_select_db($db_database_new, db_connect());
  }
  return($db_database);
  }
  ?>
  zhi yao ding yi zhe xie gong gong de han shu yi ci , ni jiu ke yi zai bu tong de di fang shi yong zhe xie gong gong de bian liang , er bu xu yao jia ru global shen ming 。 yi xia jiu shi shi yong shang mian db han shu de gong gong han shu :
  <?php
  function connect($Database = "", $Host = "", $User = "", $Password = "") {
  /* chu li mo ren lian jie */
  if ("" == $Database) {
  $Database = $this->Database;
  }
  if ("" == $Host) {
  $Host = $this->Host;
  }
  if ("" == $User) {
  $User = $this->User;
  }
  if ("" == $Password) {
  $Password = $this->Password;
  }
  /* jian li lian jie , xuan ze shu ju ku */
  if ( 0 == db_connect()) {
  $this->Link_ID = db_connect($Host, $User, $Password);
  if (!$this->Link_ID) {
  $this->halt("pconnect($Host, $User, $Password) failed.");
  return 0;
  }
  }
  if (0 != db_connect()) {
  if($Database != db_database()) {
  $this->Database = db_database($Database))
  if(empty($this->Database)) {
  $this->halt("cannot use database " . $this->Database);
  return 0;
  }
  }
  }
  return $this->Link_ID;
  }
  ?>
  liu yi yi xia gai bian :
  dui shu ju ku de ce shi cong lian jie de ce shi zhong fen li chu lai , zhe yang ji shi connect() you yi ge dang qian lian jie shi , huan ke yi jian cha shi fou yao huan cheng ling wai de shu ju ku 。 zhe yi wei zhe yu yi qian xiang bi ,db_connect() he 0 zuo bi jiao de ci shu duo le yi bei , bu guo zhe ge e wai de chu li shi bi yao de 。
  wo men jiang shu ju ku lian jie he shu ju ku xuan ze fang zai PHPLIB wai , zhe yang ni jiu ke yi zai PHP dai ma de ren he di fang shi yong tong yang de shu ju ku xuan ze han shu 。
  bu guo , xian zai de chu li you yi ge xian zhi , zhe li wo men shi jia ding dui yu suo you de shu ju ku , dou shi yong tong yang de zhu ji 、 yong hu he mi ma 。 ru guo ni de shu ju ku dui yu bu tong de yong hu you bu tong de quan xian , ni bi xu jian li yi ge te bie de lian jie lai fang wen ta 。 zen yang zuo ? zhi yao ding yi yi xia bian liang jiu ke yi le :
  <?php
  $db_host = "";
  $db_user = "";
  $db_pass = "";
  ?>
  tong guo kuo zhan db_database() han shu , jiang dang qian de yong hu he zhu ji he mou ge yong hu he zhu ji zuo dui bi jiu xing 。 ni huan ke yi jia ru :
  <?php
  $db_type = "";
  ?>
  zhe ge bian liang yong lai cun chu shu ju ku de lei xing ,mysql huo zhe Oracle deng 。 zhe yang ni jiu ke yi fang wen duo ge shu ju ku 。
  bu guo yao gai bian dai ma lai chu li duo ge bu tong lei xing de shu ju ku shi po fu duo de 。 ni bi xu huan yao gai bian cha xun han shu , yi ji lian jie he xuan ze han shu 。 ni huo xu ke tong guo PHP de ODBC lai lian jie , ran hou shi yong PHPLIB de ODBC xuan xiang lai chu li 。ODBC tong guo yi ge tong yong de fang shi lai chu li duo zhong shu ju ku , yin ci jiang hui man yi dian 。ODBC sui ran ke rang ni shi yong tong yang de dai ma lai chu li duo ge bu tong lei xing de shu ju ku 。 dan shi zai xu yao yong dao bu tong chu li ge shi de ri qi shi , jiang hui you wen ti , er qie zai shu ju ku jian ye hui cun zai yi xie qi guai de cha yi 。ODBC zhi shi jian hua le lian jie , dan shi bing mei you xiu gai shu ju ku jie shi shu ju he SQL de fang shi 。
  xian zai lai xue xi yi xia ru he chong xin ding yi yi ge dui xiang lei 。connect() han shu bei feng zhuang dao yi ge lei de ding yi zhong :
  <?php
  class DB_Sql {
  }
  ?>
  wo men jiang gai han shu kao bei dao common.php shi , wo men bi xu chong xin ding yi DB_Sql lei , wo men ke yi zhe yang feng zhuang connect():
  <?php
  class db_DB_Sql extends DB_Sql {
  }
  ?>
  yao xiang xi le jie "extends" de gong zuo , wo men ke yi kan kan PHP wen dang zhong guan yu dui xiang he lei de bu fen 。 jian dan shuo lai : kuo zhan bu fen de ren he ding yi ti huan he fu gai le yi qian de suo you ding yi 。
  xian zai ke yi shi yong db_DB_Sql。 zai ni pei zhi PHPLIB shi , ni yao zuo yi xia sheng ming :
  <?php
  $x = new DB_Sql;
  ?> Change it to: <?php
  $x = new db_DB_Sql;
  ?>
  zhe yang ni jiu ke yi shi yong xiu gai de lei , er bu shi yi qian de lei 。
  zai lian jie shu ju ku chu cuo de shi hou , ni ke yi zai wai bu de han shu zhong shu chu mu qian de lian jie zhuang tai 。 ru guo SQL yu ju chu cuo , ni ye ke yi jiang DB_Sql zhong de query() han shu kao bei dao common.PHP de db_DB_Sql zhong , ran hou cha ru yi ge shu chu yu ju , kan kan dang qian de SQL yu ju shi shen me 。
  ni ye ke yi jiang cuo wu huo zhe zhen duan de xin xi xie dao yi ge ci pan wen jian zhong 。 tong guo ding yi
  $db_log_file = "t:/diag.txt";
  huo zhe yi ge lei si de wen ben wen jian 。 ru guo shi yong Windows, ni yao que bao gai mu lu cun zai , fou ze ni hui de dao yi ge cuo wu de xin xi 。
  ran hou ding yi yi ge han shu :
  <?php
  function db_log($db_log_message) {
  globals $db_log_file;
  $db_log_f = fopen($db_log_file, "a");
  fwrite($db_log_f, date("Y m d H:i:s")." ".$db_log_message."rn");
  fclose($db_log_f);
  }
  ?>
  zai ni xu yao ji lu xin xi de di fang , jia ru yi xia dai ma :
  <?php
  db_log("current database: " . db_database());
  ?>
  qi shi ni ke yi shi yong nei zhi de huo zhe xi tong de ri zhi wen jian 。 bu guo zhe yang ni jiu yao zai yi da dui de wen jian zhong cha zhao yi xiao duan xin xi 。 yin ci zhe ge du li de ji lu wen jian ke bang zhu ni jin xing ce shi 。 wo jian yi zai ji lu qian hou xie yi xia de dai ma :
  <?php
  db_log("current database: " . db_database());
  db_database("bookcatalogue");
  db_log("current database: " . db_database());
  ?>
  zai shu ju fang wen shi , yao ji de shi yong zheng que de shu ju ku , er bu shi PHPLIB zhong ding yi de shu ju ku 。 ni ke yi wei gai shu ju ku chuang jian yi ge feng zhuang de han shu , huo zhe gai bian ni shi yong de han shu 。 ru guo ni shi yong mysql_query(), ni ke yi xian yong db_database(), ni ke yi yong
  <?php
  $result = mysql_db_query(db_database("bookcatalogue"), "select * from?",
  db_connect());
  ?> which suggests the function: <?php
  function db_query($db_query_database, $db_query_sql) {
  return(mysql_db_query(db_database($db_query_database), $db_query_sql,
  db_connect());
  }
  ?>
  lai dai ti
  <?php
  db_database("bookcatalogue");
  $result = mysql_query("select * from?", db_connect());
  ?>
  xian zai ni ke yi zuo dao
  . shi yong PHPLIB( huo zhe lei si de ruan jian ) lai fang wen duo ge shu ju ku
  . kuo zhan lei / dui xiang
  . cha ru zhen duan jian cha
  . jian li ri zhi wen jian【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
PHPLIB shi PHP de yi xie kuo zhan ku , shi yong ta wo men ke yi hen fang bian di dui shu ju ku jin xing ge zhong cao zuo , bu guo , ru guo ni yao shi yong duo ge shu ju ku de hua , ta jiu xian de li bu cong xin le , ben wen jie shao le tong guo kuo zhan PHPLIB, rang ni yu he xiong zhang jian de , zai shi yong PHPLIB de tong shi ke yi shi yong duo ge shu ju ku , er qie cong zhong ni ye ke yi le jie dao mian xiang dui xiang bian cheng he ru he kuo zhan ku de zhi shi , zhi de yi du 。 shu ju ku guan li    ni ke yi zai yi ge da xing de shu ju ku zhong fang ru ren he biao 。 bu guo shi jian chang le , jiang hui ling shu ju ku bian de yue lai yue da , fu wu qi ke neng hui gen bu shang IO de gong zuo , huo zhe mei you zu gou de nei cun ying fu suo you de fang wen ? yao fen kai xian you de shu ju you fei chang nan 。 ming zhi de ban fa shi kai shi shi jiu shi yong fen kai de shu ju ku , bing qie jin xing you xiao de shu ju ku guan li 。 ru guo ni you yi ge mai shu de wang zhan , ni ke neng you zuo zhe de lie biao , shu jia de lie biao , huan you dang qian de ku cun he ding dan de lie biao 。 dang ni de ye wu bu duan zeng chang shi , ding dan jiang hui bu duan di zeng chang , er qie chu li mei ge ding dan dou xu yao jin xing hen duo de ci pan fang wen 。 hen ke neng ni jiang zai mou yi tian jiang suo you de ding dan dou fang dao yi ge hui ji xi tong zhong 。    xian zai jiu jiang ding dan fang dao yi ge du li de shu ju ku ba 。 you yu ku cun ye shi tong guo ding dan geng xin de , yin ci ku cun liang ye fang dao tong yang de shu ju ku zhong 。    zuo zhe de lie biao he shu de lie biao dou shi yi xie jing tai de xin xi , yao jing chang du qu , dan hen shao geng xin 。 shi ji shang , geng xin yi ge zuo zhe de ji lu ke neng zhi xu yao mei 5 nian yi ci , zhi zai zuo zhe xie le yi ben xin shu ( huo zhe qu shi ) shi jin xing 。 fang zhe xie shu ju de fu wu qi de pei zhi ke yu fang ding dan shu ju ku de fu wu qi wan quan bu tong 。 bao han PHPLIB   PHPLIB tong guo yi ge cheng wei DB_Sql de lei fang wen SQL shu ju ku 。 gen ju ni xu yao shi yong de shu ju ku lei xing , jiang bu tong de inc wen jian bao han zai ni de dai ma zhong 。 zai zhe ge li zi zhong , wo shi yong MySQL de ban ben 。    wei le zai ni de dai ma zhong shi yong DB_Sql, yao jiang PHPLIB wen jian an zhuang zai ta men zi ji de mu lu zhong 。 ran hou , zhao dao ni de cgi-bin mu lu , bing qie zai cgi-bin de mu lu pang chuang jian phplib mu lu 。 xia yi bu , kao bei suo you de PHPLIB .inc wen jian dao phplib mu lu 。 zui hou , xiu gai php.inc wen jian , zhi yao jiang “include_path=” de xing gai wei gai phplib mu lu jiu ke yi le 。 include_path shi PHP shi yong include() huo zhe require() shi cha zhao de mu lu , zai wo de NT workstation zhong ,include de lu jing shi : include_path = ".;i:/project52/includes;i:/project52/phplib"; zai Linux de xi tong shang include_path = ".;/home/httpd/includes;/home/httpd/phplib"; zai mei ge PHP ye mian de ding bu jia ru <?php require(common.php); ?> common.php3 fang zai includes mu lu zhong , bao han le mei ge ye mian yao yong dao de suo you shu ju he han shu 。 zai zhe ge li zi zhong de common.php shi : <?php require(db_mysql.inc); require(ct_sql.inc); require(session.inc); require(auth.inc); require(perm.inc); require(user.inc); require(page.inc); ?>    ru guo ni xiang zhi dao mei ge inc wen jian de yong chu , ke yue du [url=http://phplib.netuse.de]http://phplib.netuse.de[/url] shang de PHPLIB wen dang 。Db_mysql.inc bao han le suo you DB_SQL lei de ding yi 。 ru guo ni xiang shi yong PostGreSQL dai ti MySQL, zhi yao yong db_pgsql.inc dai ti db_mysql.inc jiu ke yi le 。 huan you 10 ge qi ta de .inc wen jian , ke yi shi yong MS SQL、Oracle、Sybase huo zhe qi ta de shu ju ku 。    yao zhu yi de shi , zai zhe ge li zi zhong ,require() he include() shi wan quan yi yang de 。 bu guo , ru guo fang zai dai ma zhong , huo zhe zai if yu ju zhong shi yong shi ,Require() he include de shi yong shi wan quan bu tong de , bing qie you bu tong de yun xing jie guo 。 kuo zhan PHPLIB   PHPLIB tong guo yi ge DB_Sql lei chan sheng de dui xiang lai fang wen shu ju ku 。Db_mysql.inc bao han le wei MySQL xiu gai guo de DB_Sql lei 。 wo men jiang tong guo zai common.php zhong jia ru dai ma lai kuo zhan DB_sql, zhe xie dai ma jiang jia zai bao han db_mysql.inc de xing hou 。 DB_Sql bao han le hen duo yong zuo cha xun de han shu , wo men yao zuo xiu gai de shi : <?php /* public: lian jie guan li */ function connect($Database = "", $Host = "", $User = "", $Password = "") { /* chu li mo ren lian jie */ if ("" == $Database) $Database = $this->Database; if ("" == $Host) $Host = $this->Host; if ("" == $User) $User = $this->User; if ("" == $Password) $Password = $this->Password; /* jian li lian jie , xuan ze shu ju ku */ if ( 0 == $this->Link_ID ) { $this->Link_ID=mysql_pconnect($Host, $User, $Password); if (!$this->Link_ID) { $this->halt("pconnect($Host, $User, $Password) failed."); return 0; } if ([url=mailto:!@mysql_select_db($Database,$this-]Link_ID"!@mysql_select_db($Database,$this->Link_ID[/url])) { $this->halt("cannot use database ".$this->Database); return 0; } } return $this->Link_ID; } ?>    zai ni de db_mysql.inc( huo zhe qi ta shu ju ku de xiang guan .inc wen jian ) zhong zhao dao connect() han shu , ran hou jiang ta kao bei dao common.php, fang dao bao han db_mysql.inc dai ma de hou mian , zai hou mian , huan yao jiang ta feng zhuang wei yi ge lei de ding yi 。 wo fa xian zhe xie dai ma you xie nan du , yin ci , shou xian ling kao bei lai de dai ma de ke du xing geng hao : <?php /* public: lian jie guan li */ function connect($Database = "", $Host = "", $User = "", $Password = "") { /* chu li mo ren lian jie */ if ("" == $Database) { $Database = $this->Database; } if ("" == $Host) { $Host = $this->Host; } if ("" == $User) { $User = $this->User; } if ("" == $Password) { $Password = $this->Password; } /* jian li lian jie , xuan ze shu ju ku */ if ( 0 == $this->Link_ID ) { $this->Link_ID=mysql_pconnect($Host, $User, $Password); if (!$this->Link_ID) { $this->halt("pconnect($Host, $User, $Password) failed."); return 0; } if ([url=mailto:!@mysql_select_db($Database,$this-]Link_ID"!@mysql_select_db($Database,$this->Link_ID[/url])) { $this->halt("cannot use database ".$this->Database); return 0; } } return $this->Link_ID; } ?>    wo tiao zheng le yi xia kuo hao de wei zhi , bing qie zai dan xing de qian hou ye jia ru le yi ge da kuo hao 。 zai PHP de if yu ju zhong , ru guo zhi you yi ju dai ma de hua ni ke yi bu yong kuo hao , dan shi , ru guo ni zeng jia duo yi xing dai ma , jiu hui ma shang chu cuo 。 yin ci wo jian yi ni jia ru yi ge kuo hao , yi mian hou lai jia ru dai ma shi chu cuo 。    zai gai bian connect de dai ma zhi qian , xian yao le jie yi xia connect() shi ru he gong zuo de , ta jian cha dang qian shi fou cun zai yi ge lian jie , ru guo bu cun zai lian jie de hua , jiu chuang jian yi ge lian jie 。 zai mei ci de shu ju ku cha xun zhi qian , shou xian yun xing zhe ge connect() han shu 。 ke xi de shi , ta zhi zai shou ci lian jie de shi hou xuan ze shu ju ku , ru guo ni de PHP ye mian shi yong chao guo yi ge shu ju ku ,connect() bing bu hui xuan ze ling wai de shu ju ku 。    yao gai bian dai ma de hua , you ji zhong bu tong de fang fa 。 wo men yao xuan ze yi zhong dui PHPLIB de ying xiang zui xiao , er qie ke rang wo men zai xu yao fen xi wen ti de shi hou , neng gou xian shi shu ju ku lian jie zhuang tai de fang fa 。 wo men xu yao zai PHPLIB wai bao cun lian jie id he shu ju ku de ming zi 。 zhi yao zai common.php jia ru : <?php $db_connection = 0; // shu ju ku lian jie de id $db_database = ""; // dang qian shu ju ku de zhuang tai ?>    xia yi bu , wo men yao dui PHPLIB zuo xiu gai , yi bian zai zhe xie bian liang zhong cun chu lian jie id he shu ju ku de ming zi 。 zai qi ta de dai ma zhong , ni ke yi she zhi he shi yong tong yang de bian liang ming 。 zai fen xi wen ti shi , ru guo ni xu yao zhi dao xian zai shi yong na ge shu ju ku , zhi yao zai ye mian zhong cha ru yi xia de dai ma : <?php Print(" db_database: " . $db_database . ""); ?> wo men zen yang cai neng rang connect() shi yong zhe xie xin bian liang ne ? wo men ke yi zai ding bu jia ru yi xing : <?php { globals $db_connect, $db_database; /* Handle defaults */ ?> tong guo zhe xie dai ma , xin bian liang jiu ke bei connect() fang wen dao zai ding yi le $db_database hou , jia ru : <?php function db_connect($db_connect_host="", $db_connect_user="",$db_connect_pass="") { globals $db_connect; if(!empty($db_connect_host)) { $db_connect = mysql_pconnect($db_connect_host, $db_connect_user, $db_connect_pass); } return($db_connect); } function db_database($db_database_new="") { globals $db_database; if(!empty($db_database_new)) { $db_database = @mysql_select_db($db_database_new, db_connect()); } return($db_database); } ?>    zhi yao ding yi zhe xie gong gong de han shu yi ci , ni jiu ke yi zai bu tong de di fang shi yong zhe xie gong gong de bian liang , er bu xu yao jia ru global shen ming 。 yi xia jiu shi shi yong shang mian db han shu de gong gong han shu : <?php function connect($Database = "", $Host = "", $User = "", $Password = "") { /* chu li mo ren lian jie */ if ("" == $Database) { $Database = $this->Database; } if ("" == $Host) { $Host = $this->Host; } if ("" == $User) { $User = $this->User; } if ("" == $Password) { $Password = $this->Password; } /* jian li lian jie , xuan ze shu ju ku */ if ( 0 == db_connect()) { $this->Link_ID = db_connect($Host, $User, $Password); if (!$this->Link_ID) { $this->halt("pconnect($Host, $User, $Password) failed."); return 0; } } if (0 != db_connect()) { if($Database != db_database()) { $this->Database = db_database($Database)) if(empty($this->Database)) { $this->halt("cannot use database " . $this->Database); return 0; } } } return $this->Link_ID; } ?> liu yi yi xia gai bian :    dui shu ju ku de ce shi cong lian jie de ce shi zhong fen li chu lai , zhe yang ji shi connect() you yi ge dang qian lian jie shi , huan ke yi jian cha shi fou yao huan cheng ling wai de shu ju ku 。 zhe yi wei zhe yu yi qian xiang bi ,db_connect() he 0 zuo bi jiao de ci shu duo le yi bei , bu guo zhe ge e wai de chu li shi bi yao de 。    wo men jiang shu ju ku lian jie he shu ju ku xuan ze fang zai PHPLIB wai , zhe yang ni jiu ke yi zai PHP dai ma de ren he di fang shi yong tong yang de shu ju ku xuan ze han shu 。    bu guo , xian zai de chu li you yi ge xian zhi , zhe li wo men shi jia ding dui yu suo you de shu ju ku , dou shi yong tong yang de zhu ji 、 yong hu he mi ma 。 ru guo ni de shu ju ku dui yu bu tong de yong hu you bu tong de quan xian , ni bi xu jian li yi ge te bie de lian jie lai fang wen ta 。 zen yang zuo ? zhi yao ding yi yi xia bian liang jiu ke yi le : <?php $db_host = ""; $db_user = ""; $db_pass = ""; ?>    tong guo kuo zhan db_database() han shu , jiang dang qian de yong hu he zhu ji he mou ge yong hu he zhu ji zuo dui bi jiu xing 。 ni huan ke yi jia ru : <?php $db_type = ""; ?>    zhe ge bian liang yong lai cun chu shu ju ku de lei xing ,mysql huo zhe Oracle deng 。 zhe yang ni jiu ke yi fang wen duo ge shu ju ku 。    bu guo yao gai bian dai ma lai chu li duo ge bu tong lei xing de shu ju ku shi po fu duo de 。 ni bi xu huan yao gai bian cha xun han shu , yi ji lian jie he xuan ze han shu 。 ni huo xu ke tong guo PHP de ODBC lai lian jie , ran hou shi yong PHPLIB de ODBC xuan xiang lai chu li 。ODBC tong guo yi ge tong yong de fang shi lai chu li duo zhong shu ju ku , yin ci jiang hui man yi dian 。ODBC sui ran ke rang ni shi yong tong yang de dai ma lai chu li duo ge bu tong lei xing de shu ju ku 。 dan shi zai xu yao yong dao bu tong chu li ge shi de ri qi shi , jiang hui you wen ti , er qie zai shu ju ku jian ye hui cun zai yi xie qi guai de cha yi 。ODBC zhi shi jian hua le lian jie , dan shi bing mei you xiu gai shu ju ku jie shi shu ju he SQL de fang shi 。    xian zai lai xue xi yi xia ru he chong xin ding yi yi ge dui xiang lei 。connect() han shu bei feng zhuang dao yi ge lei de ding yi zhong : <?php class DB_Sql { } ?> wo men jiang gai han shu kao bei dao common.php shi , wo men bi xu chong xin ding yi DB_Sql lei , wo men ke yi zhe yang feng zhuang connect(): <?php class db_DB_Sql extends DB_Sql { } ?>    yao xiang xi le jie "extends" de gong zuo , wo men ke yi kan kan PHP wen dang zhong guan yu dui xiang he lei de bu fen 。 jian dan shuo lai : kuo zhan bu fen de ren he ding yi ti huan he fu gai le yi qian de suo you ding yi 。 xian zai ke yi shi yong db_DB_Sql。 zai ni pei zhi PHPLIB shi , ni yao zuo yi xia sheng ming : <?php $x = new DB_Sql; ?> Change it to: <?php $x = new db_DB_Sql; ?> zhe yang ni jiu ke yi shi yong xiu gai de lei , er bu shi yi qian de lei 。    zai lian jie shu ju ku chu cuo de shi hou , ni ke yi zai wai bu de han shu zhong shu chu mu qian de lian jie zhuang tai 。 ru guo SQL yu ju chu cuo , ni ye ke yi jiang DB_Sql zhong de query() han shu kao bei dao common.PHP de db_DB_Sql zhong , ran hou cha ru yi ge shu chu yu ju , kan kan dang qian de SQL yu ju shi shen me 。 ni ye ke yi jiang cuo wu huo zhe zhen duan de xin xi xie dao yi ge ci pan wen jian zhong 。 tong guo ding yi $db_log_file = "t:/diag.txt"; huo zhe yi ge lei si de wen ben wen jian 。 ru guo shi yong Windows, ni yao que bao gai mu lu cun zai , fou ze ni hui de dao yi ge cuo wu de xin xi 。 ran hou ding yi yi ge han shu : <?php function db_log($db_log_message) { globals $db_log_file; $db_log_f = fopen($db_log_file, "a"); fwrite($db_log_f, date("Y m d H:i:s")." ".$db_log_message."rn"); fclose($db_log_f); } ?> zai ni xu yao ji lu xin xi de di fang , jia ru yi xia dai ma : <?php db_log("current database: " . db_database()); ?>    qi shi ni ke yi shi yong nei zhi de huo zhe xi tong de ri zhi wen jian 。 bu guo zhe yang ni jiu yao zai yi da dui de wen jian zhong cha zhao yi xiao duan xin xi 。 yin ci zhe ge du li de ji lu wen jian ke bang zhu ni jin xing ce shi 。 wo jian yi zai ji lu qian hou xie yi xia de dai ma : <?php db_log("current database: " . db_database()); db_database("bookcatalogue"); db_log("current database: " . db_database()); ?>    zai shu ju fang wen shi , yao ji de shi yong zheng que de shu ju ku , er bu shi PHPLIB zhong ding yi de shu ju ku 。 ni ke yi wei gai shu ju ku chuang jian yi ge feng zhuang de han shu , huo zhe gai bian ni shi yong de han shu 。 ru guo ni shi yong mysql_query(), ni ke yi xian yong db_database(), ni ke yi yong <?php $result = mysql_db_query(db_database("bookcatalogue"), "select * from?", db_connect()); ?> which suggests the function: <?php function db_query($db_query_database, $db_query_sql) { return(mysql_db_query(db_database($db_query_database), $db_query_sql, db_connect()); } ?> lai dai ti <?php db_database("bookcatalogue"); $result = mysql_query("select * from?", db_connect()); ?> xian zai ni ke yi zuo dao . shi yong PHPLIB( huo zhe lei si de ruan jian ) lai fang wen duo ge shu ju ku . kuo zhan lei / dui xiang . cha ru zhen duan jian cha . jian li ri zhi wen jian
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
时尚秀气模特裴裴(8)
时尚秀气模特裴裴(7)
时尚秀气模特裴裴(6)
时尚秀气模特裴裴(5)
白墙黑瓦
广州东郊[原创]
八美至丹巴的东谷天然盆景
不一样的
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有