dbd::mysql.3

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· 3 代码 · 共 1,260 行 · 第 1/3 页

3
1,260 行
字号
.IP "\(bu" 4Switching AutoCommit mode from on to off or vice versa may fail.You should always check for errors, when changing AutoCommit mode.The suggested way of doing so is using the \s-1DBI\s0 flag RaiseError.If you don't like RaiseError, you have to use code like thefollowing:.Sp.Vb 4\&  $dbh\->{\*(AqAutoCommit\*(Aq} = 0;\&  if ($dbh\->{\*(AqAutoCommit\*(Aq}) {\&    # An error occurred!\&  }.Ve.IP "\(bu" 4If you detect an error while changing the AutoCommit mode, youshould no longer use the database handle. In other words, youshould disconnect and reconnect again, because the transactionmode is unpredictable. Alternatively you may verify the transactionmode by checking the value of the server variable autocommit.However, such behaviour isn't portable..IP "\(bu" 4DBD::mysql has a \*(L"reconnect\*(R" feature that handles the so-calledMySQL \*(L"morning bug\*(R": If the server has disconnected, most probablydue to a timeout, then by default the driver will reconnect andattempt to execute the same \s-1SQL\s0 statement again. However, thisbehaviour is disabled when AutoCommit is off: Otherwise thetransaction state would be completely unpredictable after areconnect..IP "\(bu" 4The \*(L"reconnect\*(R" feature of DBD::mysql can be toggled by using themysql_auto_reconnect attribute. This behaviour should be turned offin code that uses \s-1LOCK\s0 \s-1TABLE\s0 because if the database server time outand DBD::mysql reconnect, table locks will be lost without any indication of such loss..SH "MULTIPLE RESULT SETS".IX Header "MULTIPLE RESULT SETS"As of version 3.0002_5, DBD::mysql supports multiple result sets (Thanksto Guy Harrison!). This is the first release of this functionality, so there may be issues. Please report bugs if you run into them!.PPThe basic usage of multiple result sets is.PP.Vb 7\&  do \&  {\&    while (@row= $sth\->fetchrow_array())\&    {\&      do stuff;\&    }\&  } while ($sth\->more_results).Ve.PPAn example would be:.PP.Vb 1\&  $dbh\->do("drop procedure if exists someproc") or print $DBI::errstr;\&\&  $dbh\->do("create procedure somproc() deterministic\&   begin\&   declare a,b,c,d int;\&   set a=1;\&   set b=2;\&   set c=3;\&   set d=4;\&   select a, b, c, d;\&   select d, c, b, a;\&   select b, a, c, d;\&   select c, b, d, a;\&  end") or print $DBI::errstr;\&\&  $sth=$dbh\->prepare(\*(Aqcall someproc()\*(Aq) || \&  die $DBI::err.": ".$DBI::errstr;\&\&  $sth\->execute || die DBI::err.": ".$DBI::errstr; $rowset=0;\&  do {\&    print "\enRowset ".++$i."\en\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\en\en";\&    foreach $colno (0..$sth\->{NUM_OF_FIELDS}) {\&      print $sth\->{NAME}\->[$colno]."\et";\&    }\&    print "\en";\&    while (@row= $sth\->fetchrow_array())  {\&      foreach $field (0..$#row) {\&        print $row[$field]."\et";\&      }\&      print "\en";\&    }\&  } until (!$sth\->more_results).Ve.PPFor more examples, please see the eg/ directory. This is where helpfulDBD::mysql code snippits will be added in the future..Sh "Issues with Multiple result sets".IX Subsection "Issues with Multiple result sets"So far, the main issue is if your result sets are \*(L"jagged\*(R", meaning, thenumber of columns of your results vary. Varying numbers of columns couldresult in your script crashing. This is something that will be fixed soon..SH "MULTITHREADING".IX Header "MULTITHREADING"The multithreading capabilities of DBD::mysql depend completelyon the underlying C libraries: The modules are working with handle dataonly, no global variables are accessed or (to the best of my knowledge)thread unsafe functions are called. Thus DBD::mysql is believedto be completely thread safe, if the C libraries are thread safeand you don't share handles among threads..PPThe obvious question is: Are the C libraries thread safe?In the case of MySQL the answer is \*(L"mostly\*(R" and, in theory, you shouldbe able to get a \*(L"yes\*(R", if the C library is compiled for being threadsafe (By default it isn't.) by passing the option \-with\-thread\-safe\-clientto configure. See the section on \fIHow to make a threadsafe client\fR inthe manual..SH "INSTALLATION".IX Header "INSTALLATION"Windows users may skip this section and pass over to \s-1WIN32\s0\&\s-1INSTALLATION\s0 below. Others, go on reading..PPFirst of all, you do not need an installed MySQL server for installingDBD::mysql. However, you need at least the clientlibraries and possibly the header files, if you are compiling DBD::mysqlfrom source. In the case of MySQL you can create aclient-only version by using the configure option \-\-without\-server.If you are using precompiled binaries, then it may be possible touse just selected \s-1RPM\s0's like MySQL-client and MySQL-devel or somethingsimilar, depending on the distribution..PPFirst you need to install the \s-1DBI\s0 module. For using \fIdbimon\fR, asimple \s-1DBI\s0 shell it is recommended to install Data::ShowTable anotherPerl module..PPI recommend trying automatic installation via the \s-1CPAN\s0 module. Try.PP.Vb 1\&  perl \-MCPAN \-e shell.Ve.PPIf you are using the \s-1CPAN\s0 module for the first time, it will promptyou a lot of questions. If you finally receive the \s-1CPAN\s0 prompt, enter.PP.Vb 1\&  install Bundle::DBD::mysql.Ve.PPIf this fails (which may be the case for a number of reasons, forexample because you are behind a firewall or don't have networkaccess), you need to do a manual installation. First of all youneed to fetch the modules from \s-1CPAN\s0 search.PP.Vb 1\&   http://search.cpan.org/.Ve.PPThe following modules are required.PP.Vb 3\&  DBI\&  Data::ShowTable\&  DBD::mysql.Ve.PPThen enter the following commands (note \- versions are just examples):.PP.Vb 6\&  gzip \-cd DBI\-(version).tar.gz | tar xf \-\&  cd DBI\-(version)\&  perl Makefile.PL\&  make\&  make test\&  make install\&\&  cd ..\&  gzip \-cd Data\-ShowTable\-(version).tar.gz | tar xf \-\&  cd Data\-ShowTable\-3.3\&  perl Makefile.PL\&  make\&  make install\&\&  cd ..\&  gzip \-cd DBD\-mysql\-(version)\-tar.gz | tar xf \-\&  cd DBD\-mysql\-(version)\&  perl Makefile.PL\&  make\&  make test\&  make install.Ve.PPDuring \*(L"perl Makefile.PL\*(R" you will be prompted some questions.Other questions are the directories with header files and libraries.For example, of your file \fImysql.h\fR is in \fI/usr/include/mysql/mysql.h\fR,then enter the header directory \fI/usr\fR, likewise for\&\fI/usr/lib/mysql/libmysqlclient.a\fR or \fI/usr/lib/libmysqlclient.so\fR..SH "WIN32 INSTALLATION".IX Header "WIN32 INSTALLATION"If you are using ActivePerl, you may use ppm to install DBD-mysql.For Perl 5.6, upgrade to Build 623 or later, then it is sufficientto run.PP.Vb 2\&  ppm install DBI\&  ppm install DBD::mysql.Ve.PPIf you need an \s-1HTTP\s0 proxy, you might need to set the environmentvariable http_proxy, for example like this:.PP.Vb 1\&  set http_proxy=http://myproxy.com:8080/.Ve.PPAs of this writing, DBD::mysql is missing in the ActivePerl 5.8.0repository. However, Randy Kobes has kindly donated an owndistribution and the following might succeed:.PP.Vb 1\&  ppm install http://theoryx5.uwinnipeg.ca/ppms/DBD\-mysql.ppd.Ve.PPOtherwise you definitely *need* a C compiler. And it *must* be the samecompiler that was being used for compiling Perl itself. If you don'thave a C compiler, the file \s-1README\s0.win32 from the Perl sourcedistribution tells you where to obtain freely distributable C compilerslike egcs or gcc. The Perl sources are available via \s-1CPAN\s0 search.PP.Vb 1\&  http://search.cpan.org.Ve.PPI recommend using the win32clients package for installing DBD::mysqlunder Win32, available for download on www.tcx.se. The following stepshave been required for me:.IP "\-" 4The current Perl versions (5.6, as of this writing) do have a problemwith detecting the C libraries. I recommend to apply the followingpatch:.Sp.Vb 7\&  *** c:\ePerl\elib\eExtUtils\eLiblist.pm.orig Sat Apr 15 20:03:40 2000\&  \-\-\- c:\ePerl\elib\eExtUtils\eLiblist.pm      Sat Apr 15 20:03:45 2000\&  ***************\&  *** 230,235 ****\&  \-\-\- 230,239 \-\-\-\-\&      # add "$Config{installarchlib}/CORE" to default search path\&      push @libpath, "$Config{installarchlib}/CORE";\&\&  +     if ($VC  and  exists($ENV{LIB})  and  defined($ENV{LIB})) {\&  +       push(@libpath, split(/;/, $ENV{LIB}));\&  +     }\&  +\&      foreach (Text::ParseWords::quotewords(\*(Aq\es+\*(Aq, 0, $potential_libs)){\&\&        $thislib = $_;.Ve.IP "\-" 4Extract sources into \fIC:\e\fR. This will create a directory \fIC:\emysql\fRwith subdirectories include and lib..Sp\&\s-1IMPORTANT:\s0 Make sure this subdirectory is not shared by other \s-1TCX\s0files! In particular do *not* store the MySQL server in the samedirectory. If the server is already installed in \fIC:\emysql\fR,choose a location like \fIC:\etmp\fR, extract the win32clients there.Note that you can remove this directory entirely once you haveinstalled DBD::mysql..IP "\-" 4Extract the DBD::mysql sources into another directory, forexample \fIC:\esrc\esiteperl\fR.IP "\-" 4Open a \s-1DOS\s0 shell and change directory to \fIC:\esrc\esiteperl\fR..IP "\-" 4The next step is only required if you repeat building the modules: Makesure that you have a clean build tree by running.Sp.Vb 1\&  nmake realclean.Ve.SpIf you don't have \s-1VC++\s0, replace nmake with your flavour of make. Iferror messages are reported in this step, you may safely ignore them..IP "\-" 4Run.Sp.Vb 1\&  perl Makefile.PL.Ve.Spwhich will prompt you for some settings. The really important ones are:.Sp.Vb 1\&  Which DBMS do you want to use?.Ve.Spenter a 1 here (MySQL only), and.Sp.Vb 2\&  Where is your mysql installed? Please tell me the directory that\&  contains the subdir include..Ve.Spwhere you have to enter the win32clients directory, for example\&\fIC:\emysql\fR or \fIC:\etmp\emysql\fR..IP "\-" 4Continued in the usual way:.Sp.Vb 2\&  nmake\&  nmake install.Ve.PPIf you want to create a \s-1PPM\s0 package for the ActiveState Perl version, thenmodify the above steps as follows: Run.PP.Vb 3\&  perl Makefile.PL NAME=DBD\-mysql BINARY_LOCATION=DBD\-mysql.tar.gz\&  nmake ppd\&  nmake.Ve.PPOnce that is done, use tar and gzip (for example those from the CygWin32distribution) to create an archive:.PP.Vb 3\&  mkdir x86\&  tar cf x86/DBD\-mysql.tar blib\&  gzip x86/DBD\-mysql.tar.Ve.PPPut the files x86/DBD\-mysql.tar.gz and DBD\-mysql.ppd onto some \s-1WWW\s0 serverand install them by typing.PP.Vb 1\&  install http://your.server.name/your/directory/DBD\-mysql.ppd.Ve.PPin the \s-1PPM\s0 program..SH "AUTHORS".IX Header "AUTHORS"The current version of \fBDBD::mysql\fR is almost completely writtenby Jochen Wiedmann, and is now being maintained byPatrick Galbraith (\fIpatg@mysql.com\fR). The first version's author was Alligator Descartes, who was aidedand abetted by Gary Shea, Andreas Ko\*:nig and Tim Bunce amongst others..PPThe \fBMysql\fR module was originally written by Andreas Ko\*:nig<koenig@kulturbox.de>. The current version, mainly an emulationlayer, is from Jochen Wiedmann..SH "COPYRIGHT".IX Header "COPYRIGHT"This module is Large Portions Copyright (c) 2004\-2006 MySQL Patrick Galbraith, Alexey Stroganov,Large Portions Copyright (c) 2003\-2005 Rudolf Lippan; Large Portions Copyright (c) 1997\-2003 Jochen Wiedmann, with code portions Copyright (c)1994\-1997 their original authors This module isreleased under the same license as Perl itself. See the Perl \s-1README\s0for details..SH "MAILING LIST SUPPORT".IX Header "MAILING LIST SUPPORT"This module is maintained and supported on a mailing list,.PP.Vb 1\&    perl@lists.mysql.com.Ve.PPTo subscribe to this list, go to.PPhttp://lists.mysql.com/perl?sub=1.PPMailing list archives are available at.PPhttp://lists.mysql.com/perl.PPAdditionally you might try the dbi-user mailing list for questions about\&\s-1DBI\s0 and its modules in general. Subscribe via.PPdbi\-users\-subscribe@perl.org.PPMailing list archives are at.PPhttp://groups.google.com/group/perl.dbi.users?hl=en&lr=.PPAlso, the main \s-1DBI\s0 site is at.PPhttp://dbi.perl.org/.SH "ADDITIONAL DBI INFORMATION".IX Header "ADDITIONAL DBI INFORMATION"Additional information on the \s-1DBI\s0 project can be found on the WorldWide Web at the following \s-1URL:\s0.PP.Vb 1\&    http://dbi.perl.org.Ve.PPwhere documentation, pointers to the mailing lists and mailing listarchives and pointers to the most current versions of the modules canbe used..PPInformation on the \s-1DBI\s0 interface itself can be gained by typing:.PP.Vb 1\&    perldoc DBI.Ve.PPright now!.SH "BUG REPORTING, ENHANCEMENT/FEATURE REQUESTS".IX Header "BUG REPORTING, ENHANCEMENT/FEATURE REQUESTS"Please report bugs, including all the information neededsuch as DBD::mysql version, MySQL version, \s-1OS\s0 type/version, etcto this link:.PPhttp://bugs.mysql.com/.SH "POD ERRORS".IX Header "POD ERRORS"Hey! \fBThe above document had some coding errors, which are explained below:\fR.IP "Around line 1223:" 4.IX Item "Around line 1223:"\&'=item' outside of any '=over'.IP "Around line 1274:" 4.IX Item "Around line 1274:"You forgot a '=back' before '=head1'.IP "Around line 1516:" 4.IX Item "Around line 1516:"You forgot a '=back' before '=head1'

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?