dbd::mysql.3

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

3
1,260
字号
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings.  \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote.  \*(C+ will.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\.    ds -- \(*W-.    ds PI pi.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch.    ds L" "".    ds R" "".    ds C` "".    ds C' ""'br\}.el\{\.    ds -- \|\(em\|.    ds PI \(*p.    ds L" ``.    ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el       .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD.  Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\.    de IX.    tm Index:\\$1\t\\n%\t"\\$2"...    nr % 0.    rr F.\}.el \{\.    de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear.  Run.  Save yourself.  No user-serviceable parts..    \" fudge factors for nroff and troff.if n \{\.    ds #H 0.    ds #V .8m.    ds #F .3m.    ds #[ \f1.    ds #] \fP.\}.if t \{\.    ds #H ((1u-(\\\\n(.fu%2u))*.13m).    ds #V .6m.    ds #F 0.    ds #[ \&.    ds #] \&.\}.    \" simple accents for nroff and troff.if n \{\.    ds ' \&.    ds ` \&.    ds ^ \&.    ds , \&.    ds ~ ~.    ds /.\}.if t \{\.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u".    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}.    \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E.    \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'.    \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\.    ds : e.    ds 8 ss.    ds o a.    ds d- d\h'-1'\(ga.    ds D- D\h'-1'\(hy.    ds th \o'bp'.    ds Th \o'LP'.    ds ae ae.    ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "DBD::mysql 3".TH DBD::mysql 3 "2007-12-11" "perl v5.10.0" "User Contributed Perl Documentation".\" For nroff, turn off justification.  Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"DBD::mysql \- MySQL driver for the Perl5 Database Interface (DBI).SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 1\&    use DBI;\&\&    $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";\&\&    $dbh = DBI\->connect($dsn, $user, $password);\&\&\&    $drh = DBI\->install_driver("mysql");\&    @databases = DBI\->data_sources("mysql");\&       or\&    @databases = DBI\->data_sources("mysql",\&      {"host" => $host, "port" => $port, "user" => $user, password => $pass});\&\&    $sth = $dbh\->prepare("SELECT * FROM foo WHERE bla");\&       or\&    $sth = $dbh\->prepare("LISTFIELDS $table");\&       or\&    $sth = $dbh\->prepare("LISTINDEX $table $index");\&    $sth\->execute;\&    $numRows = $sth\->rows;\&    $numFields = $sth\->{\*(AqNUM_OF_FIELDS\*(Aq};\&    $sth\->finish;\&\&    $rc = $drh\->func(\*(Aqcreatedb\*(Aq, $database, $host, $user, $password, \*(Aqadmin\*(Aq);\&    $rc = $drh\->func(\*(Aqdropdb\*(Aq, $database, $host, $user, $password, \*(Aqadmin\*(Aq);\&    $rc = $drh\->func(\*(Aqshutdown\*(Aq, $host, $user, $password, \*(Aqadmin\*(Aq);\&    $rc = $drh\->func(\*(Aqreload\*(Aq, $host, $user, $password, \*(Aqadmin\*(Aq);\&\&    $rc = $dbh\->func(\*(Aqcreatedb\*(Aq, $database, \*(Aqadmin\*(Aq);\&    $rc = $dbh\->func(\*(Aqdropdb\*(Aq, $database, \*(Aqadmin\*(Aq);\&    $rc = $dbh\->func(\*(Aqshutdown\*(Aq, \*(Aqadmin\*(Aq);\&    $rc = $dbh\->func(\*(Aqreload\*(Aq, \*(Aqadmin\*(Aq);.Ve.SH "EXAMPLE".IX Header "EXAMPLE".Vb 1\&  #!/usr/bin/perl\&\&  use strict;\&  use DBI();\&\&  # Connect to the database.\&  my $dbh = DBI\->connect("DBI:mysql:database=test;host=localhost",\&                         "joe", "joe\*(Aqs password",\&                         {\*(AqRaiseError\*(Aq => 1});\&\&  # Drop table \*(Aqfoo\*(Aq. This may fail, if \*(Aqfoo\*(Aq doesn\*(Aqt exist.\&  # Thus we put an eval around it.\&  eval { $dbh\->do("DROP TABLE foo") };\&  print "Dropping foo failed: $@\en" if $@;\&\&  # Create a new table \*(Aqfoo\*(Aq. This must not fail, thus we don\*(Aqt\&  # catch errors.\&  $dbh\->do("CREATE TABLE foo (id INTEGER, name VARCHAR(20))");\&\&  # INSERT some data into \*(Aqfoo\*(Aq. We are using $dbh\->quote() for\&  # quoting the name.\&  $dbh\->do("INSERT INTO foo VALUES (1, " . $dbh\->quote("Tim") . ")");\&\&  # Same thing, but using placeholders\&  $dbh\->do("INSERT INTO foo VALUES (?, ?)", undef, 2, "Jochen");\&\&  # Now retrieve data from the table.\&  my $sth = $dbh\->prepare("SELECT * FROM foo");\&  $sth\->execute();\&  while (my $ref = $sth\->fetchrow_hashref()) {\&    print "Found a row: id = $ref\->{\*(Aqid\*(Aq}, name = $ref\->{\*(Aqname\*(Aq}\en";\&  }\&  $sth\->finish();\&\&  # Disconnect from the database.\&  $dbh\->disconnect();.Ve.SH "DESCRIPTION".IX Header "DESCRIPTION"\&\fBDBD::mysql\fR is the Perl5 Database Interface driver for the MySQLdatabase. In other words: DBD::mysql is an interface between the Perlprogramming language and the MySQL programming \s-1API\s0 that comes withthe MySQL relational database management system. Most functionsprovided by this programming \s-1API\s0 are supported. Some rarely usedfunctions are missing, mainly because noone ever requestedthem. :\-).PPIn what follows we first discuss the use of DBD::mysql,because this is what you will need the most. For installation, see thesections on \s-1INSTALLATION\s0, and \*(L"\s-1WIN32\s0 \s-1INSTALLATION\s0\*(R"below. See \s-1EXAMPLE\s0 for a simple example above..PPFrom perl you activate the interface with the statement.PP.Vb 1\&    use DBI;.Ve.PPAfter that you can connect to multiple MySQL database serversand send multiple queries to any of them via a simple object orientedinterface. Two types of objects are available: database handles andstatement handles. Perl returns a database handle to the connectmethod like so:.PP.Vb 2\&  $dbh = DBI\->connect("DBI:mysql:database=$db;host=$host",\&                      $user, $password, {RaiseError => 1});.Ve.PPOnce you have connected to a database, you can can execute \s-1SQL\s0statements with:.PP.Vb 3\&  my $query = sprintf("INSERT INTO foo VALUES (%d, %s)",\&                      $number, $dbh\->quote("name"));\&  $dbh\->do($query);.Ve.PPSee \s-1\fIDBI\s0\fR\|(3) for details on the quote and do methods. An alternativeapproach is.PP.Vb 2\&  $dbh\->do("INSERT INTO foo VALUES (?, ?)", undef,\&           $number, $name);.Ve.PPin which case the quote method is executed automatically. See alsothe bind_param method in \s-1\fIDBI\s0\fR\|(3). See \*(L"\s-1DATABASE\s0 \s-1HANDLES\s0\*(R" belowfor more details on database handles..PPIf you want to retrieve results, you need to create a so-calledstatement handle with:.PP.Vb 2\&  $sth = $dbh\->prepare("SELECT * FROM $table");\&  $sth\->execute();.Ve.PPThis statement handle can be used for multiple things. First of allyou can retreive a row of data:.PP.Vb 1\&  my $row = $sth\->fetchrow_hashref();.Ve.PPIf your table has columns \s-1ID\s0 and \s-1NAME\s0, then \f(CW$row\fR will be hash ref withkeys \s-1ID\s0 and \s-1NAME\s0. See \*(L"\s-1STATEMENT\s0 \s-1HANDLES\s0\*(R" below for more details onstatement handles..PPBut now for a more formal approach:.Sh "Class Methods".IX Subsection "Class Methods".IP "\fBconnect\fR" 4.IX Item "connect".Vb 1\&    use DBI;\&\&    $dsn = "DBI:mysql:$database";\&    $dsn = "DBI:mysql:database=$database;host=$hostname";\&    $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";\&\&    $dbh = DBI\->connect($dsn, $user, $password);.Ve.SpA \f(CW\*(C`database\*(C'\fR must always be specified..RS 4.IP "host" 4.IX Item "host".PD 0.IP "port" 4.IX Item "port".PDThe hostname, if not specified or specified as '' or 'localhost', willdefault to a MySQL server running on the local machine using the default forthe \s-1UNIX\s0 socket. To connect to a MySQL server on the local machine via \s-1TCP\s0,you must specify the loopback \s-1IP\s0 address (127.0.0.1) as the host..SpShould the MySQL server be running on a non-standard port number,you may explicitly state the port number to connect to in the \f(CW\*(C`hostname\*(C'\fRargument, by concatenating the \fIhostname\fR and \fIport number\fR togetherseparated by a colon ( \f(CW\*(C`:\*(C'\fR ) character or by using the  \f(CW\*(C`port\*(C'\fR argument..SpTo connect to a MySQL server on localhost using \s-1TCP/IP\s0, you must specify thehostname as 127.0.0.1 (with the optional port)..IP "mysql_client_found_rows" 4.IX Item "mysql_client_found_rows"Enables (\s-1TRUE\s0 value) or disables (\s-1FALSE\s0 value) the flag \s-1CLIENT_FOUND_ROWS\s0while connecting to the MySQL server. This has a somewhat funny effect:Without mysql_client_found_rows, if you perform a query like.Sp.Vb 1\&  UPDATE $table SET id = 1 WHERE id = 1.Ve.Spthen the MySQL engine will always return 0, because no rows have changed.With mysql_client_found_rows however, it will return the number of rowsthat have an id 1, as some people are expecting. (At least for compatibilityto other engines.).IP "mysql_compression" 4.IX Item "mysql_compression"As of MySQL 3.22.3, a new feature is supported: If your \s-1DSN\s0 containsthe option \*(L"mysql_compression=1\*(R", then the communication between clientand server will be compressed..IP "mysql_connect_timeout" 4.IX Item "mysql_connect_timeout"If your \s-1DSN\s0 contains the option \*(L"mysql_connect_timeout=##\*(R", the connectrequest to the server will timeout if it has not been successful afterthe given number of seconds..IP "mysql_read_default_file" 4.IX Item "mysql_read_default_file".PD 0.IP "mysql_read_default_group" 4.IX Item "mysql_read_default_group".PDThese options can be used to read a config file like /etc/my.cnf or~/.my.cnf. By default MySQL's C client library doesn't use any configfiles unlike the client programs (mysql, mysqladmin, ...) that do, butoutside of the C client library. Thus you need to explicitly requestreading a config file, as in.Sp.Vb 2\&    $dsn = "DBI:mysql:test;mysql_read_default_file=/home/joe/my.cnf";\&    $dbh = DBI\->connect($dsn, $user, $password).Ve.SpThe option mysql_read_default_group can be used to specify the defaultgroup in the config file: Usually this is the \fIclient\fR group, butsee the following example:.Sp.Vb 2\&    [client]\&    host=localhost\&\&    [perl]\&    host=perlhost.Ve.Sp(Note the order of the entries! The example won't work, if you reversethe [client] and [perl] sections!).SpIf you read this config file, then you'll be typically connected to\&\fIlocalhost\fR. However, by using.Sp.Vb 3\&    $dsn = "DBI:mysql:test;mysql_read_default_group=perl;"\&        . "mysql_read_default_file=/home/joe/my.cnf";\&    $dbh = DBI\->connect($dsn, $user, $password);.Ve.Spyou'll be connected to \fIperlhost\fR. Note that if you specify adefault group and do not specify a file, then the default configfiles will all be read.  See the documentation ofthe C function \fImysql_options()\fR for details..IP "mysql_socket" 4.IX Item "mysql_socket"As of MySQL 3.21.15, it is possible to choose the Unix socket that isused for connecting to the server. This is done, for example, with.Sp.Vb 1\&    mysql_socket=/dev/mysql.Ve.SpUsually there's no need for this option, unless you are using anotherlocation for the socket than that built into the client..IP "mysql_ssl" 4.IX Item "mysql_ssl"A true value turns on the \s-1CLIENT_SSL\s0 flag when connecting to the MySQLdatabase:.Sp.Vb 1\&  mysql_ssl=1.Ve.SpThis means that your communication with the server will be encrypted..SpIf you turn mysql_ssl on, you might also wish to use the followingflags:.IP "mysql_ssl_client_key" 4.IX Item "mysql_ssl_client_key".PD 0

⌨️ 快捷键说明

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