⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysql.pm

📁 Astercon2 开源软交换 2.2.0
💻 PM
📖 第 1 页 / 共 4 页
字号:
Similar to mysql, but type names and not numbers are returned.Whenever possible, the ANSI SQL name is preferred.=item mysql_warning_countThe number of warnings generated during execution of the SQL statement.=back=head1 TRANSACTION SUPPORTBeginning with DBD::mysql 2.0416, transactions are supported.The transaction support works as follows:=over=item *By default AutoCommit mode is on, following the DBI specifications.=item *If you execute    $dbh->{'AutoCommit'} = 0;or    $dbh->{'AutoCommit'} = 1;then the driver will set the MySQL server variable autocommit to 0 or1, respectively. Switching from 0 to 1 will also issue a COMMIT,following the DBI specifications.=item *The methods    $dbh->rollback();    $dbh->commit();will issue the commands COMMIT and ROLLBACK, respectively. AROLLBACK will also be issued if AutoCommit mode is off and thedatabase handles DESTROY method is called. Again, this is followingthe DBI specifications.=backGiven the above, you should note the following:=over=item *You should never change the server variable autocommit manually,unless you are ignoring DBI's transaction support.=item *Switching 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 DBI flag RaiseError.If you don't like RaiseError, you have to use code like thefollowing:  $dbh->{'AutoCommit'} = 0;  if ($dbh->{'AutoCommit'}) {    # An error occurred!  }=item *If 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.=item *DBD::mysql has a "reconnect" feature that handles the so-calledMySQL "morning bug": If the server has disconnected, most probablydue to a timeout, then by default the driver will reconnect andattempt to execute the same SQL statement again. However, thisbehaviour is disabled when AutoCommit is off: Otherwise thetransaction state would be completely unpredictable after areconnect.  =item *The "reconnect" feature of DBD::mysql can be toggled by using theL<mysql_auto_reconnect> attribute. This behaviour should be turned offin code that uses LOCK TABLE because if the database server time outand DBD::mysql reconnect, table locks will be lost without any indication of such loss.=back=over=head1 MULTIPLE RESULT SETSAs 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!The basic usage of multiple result sets is  do   {    while (@row= $sth->fetchrow_array())    {      do stuff;    }  } while ($sth->more_results)An example would be:  $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('call someproc()') ||   die $DBI::err.": ".$DBI::errstr;  $sth->execute || die DBI::err.": ".$DBI::errstr; $rowset=0;  do {    print "\nRowset ".++$i."\n---------------------------------------\n\n";    foreach $colno (0..$sth->{NUM_OF_FIELDS}) {      print $sth->{NAME}->[$colno]."\t";    }    print "\n";    while (@row= $sth->fetchrow_array())  {      foreach $field (0..$#row) {        print $row[$field]."\t";      }      print "\n";    }  } until (!$sth->more_results) For more examples, please see the eg/ directory. This is where helpfulDBD::mysql code snippits will be added in the future.=head2 Issues with Multiple result setsSo far, the main issue is if your result sets are "jagged", 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.=head1 MULTITHREADINGThe 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.The obvious question is: Are the C libraries thread safe?In the case of MySQL the answer is "mostly" and, in theory, you shouldbe able to get a "yes", 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 I<How to make a threadsafe client> inthe manual.=head1 INSTALLATIONWindows users may skip this section and pass over to L<WIN32INSTALLATION> below. Others, go on reading.First 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 RPM's like MySQL-client and MySQL-devel or somethingsimilar, depending on the distribution.First you need to install the DBI module. For using I<dbimon>, asimple DBI shell it is recommended to install Data::ShowTable anotherPerl module.I recommend trying automatic installation via the CPAN module. Try  perl -MCPAN -e shellIf you are using the CPAN module for the first time, it will promptyou a lot of questions. If you finally receive the CPAN prompt, enter  install Bundle::DBD::mysqlIf 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 CPAN search   http://search.cpan.org/ The following modules are required  DBI  Data::ShowTable  DBD::mysqlThen enter the following commands (note - versions are just examples):  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 installDuring "perl Makefile.PL" you will be prompted some questions.Other questions are the directories with header files and libraries.For example, of your file F<mysql.h> is in F</usr/include/mysql/mysql.h>,then enter the header directory F</usr>, likewise forF</usr/lib/mysql/libmysqlclient.a> or F</usr/lib/libmysqlclient.so>.=head1 WIN32 INSTALLATIONIf 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  ppm install DBI  ppm install DBD::mysqlIf you need an HTTP proxy, you might need to set the environmentvariable http_proxy, for example like this:  set http_proxy=http://myproxy.com:8080/As 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:  ppm install http://theoryx5.uwinnipeg.ca/ppms/DBD-mysql.ppdOtherwise 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 README.win32 from the Perl sourcedistribution tells you where to obtain freely distributable C compilerslike egcs or gcc. The Perl sources are available via CPAN search  http://search.cpan.orgI recommend using the win32clients package for installing DBD::mysqlunder Win32, available for download on www.tcx.se. The following stepshave been required for me:=over=item -The current Perl versions (5.6, as of this writing) do have a problemwith detecting the C libraries. I recommend to apply the followingpatch:  *** c:\Perl\lib\ExtUtils\Liblist.pm.orig Sat Apr 15 20:03:40 2000  --- c:\Perl\lib\ExtUtils\Liblist.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('\s+', 0, $potential_libs)){        $thislib = $_;                                                                       =item -Extract sources into F<C:\>. This will create a directory F<C:\mysql>with subdirectories include and lib.IMPORTANT: Make sure this subdirectory is not shared by other TCXfiles! In particular do *not* store the MySQL server in the samedirectory. If the server is already installed in F<C:\mysql>,choose a location like F<C:\tmp>, extract the win32clients there.Note that you can remove this directory entirely once you haveinstalled DBD::mysql.=item -Extract the DBD::mysql sources into another directory, forexample F<C:\src\siteperl>=item -Open a DOS shell and change directory to F<C:\src\siteperl>.=item -The next step is only required if you repeat building the modules: Makesure that you have a clean build tree by running  nmake realcleanIf you don't have VC++, replace nmake with your flavour of make. Iferror messages are reported in this step, you may safely ignore them.=item -Run  perl Makefile.PLwhich will prompt you for some settings. The really important ones are:  Which DBMS do you want to use?enter a 1 here (MySQL only), and  Where is your mysql installed? Please tell me the directory that  contains the subdir include.where you have to enter the win32clients directory, for exampleF<C:\mysql> or F<C:\tmp\mysql>.=item -Continued in the usual way:  nmake  nmake install=backIf you want to create a PPM package for the ActiveState Perl version, thenmodify the above steps as follows: Run  perl Makefile.PL NAME=DBD-mysql BINARY_LOCATION=DBD-mysql.tar.gz  nmake ppd  nmakeOnce that is done, use tar and gzip (for example those from the CygWin32distribution) to create an archive:  mkdir x86  tar cf x86/DBD-mysql.tar blib  gzip x86/DBD-mysql.tarPut the files x86/DBD-mysql.tar.gz and DBD-mysql.ppd onto some WWW serverand install them by typing  install http://your.server.name/your/directory/DBD-mysql.ppdin the PPM program.=head1 AUTHORSThe current version of B<DBD::mysql> is almost completely writtenby Jochen Wiedmann, and is now being maintained byPatrick Galbraith (I<patg@mysql.com>). The first version's author was Alligator Descartes, who was aidedand abetted by Gary Shea, Andreas K鰊ig and Tim Bunce amongst others.The B<Mysql> module was originally written by Andreas K鰊ig<koenig@kulturbox.de>. The current version, mainly an emulationlayer, is from Jochen Wiedmann.=head1 COPYRIGHTThis 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 READMEfor details.=head1 MAILING LIST SUPPORTThis module is maintained and supported on a mailing list,    perl@lists.mysql.comTo subscribe to this list, go tohttp://lists.mysql.com/perl?sub=1Mailing list archives are available athttp://lists.mysql.com/perlAdditionally you might try the dbi-user mailing list for questions aboutDBI and its modules in general. Subscribe viadbi-users-subscribe@perl.orgMailing list archives are athttp://groups.google.com/group/perl.dbi.users?hl=en&lr=Also, the main DBI site is athttp://dbi.perl.org/=head1 ADDITIONAL DBI INFORMATIONAdditional information on the DBI project can be found on the WorldWide Web at the following URL:    http://dbi.perl.orgwhere documentation, pointers to the mailing lists and mailing listarchives and pointers to the most current versions of the modules canbe used.Information on the DBI interface itself can be gained by typing:    perldoc DBIright now!=head1 BUG REPORTING, ENHANCEMENT/FEATURE REQUESTSPlease report bugs, including all the information neededsuch as DBD::mysql version, MySQL version, OS type/version, etcto this link:http://bugs.mysql.com/=cut

⌨️ 快捷键说明

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