<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >MySQL Functions (PDO_MYSQL)</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="函数参考" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="mysql_unbuffered_query" HREF="function.mysql-unbuffered-query.html"><LINK REL="NEXT" TITLE="PDO_MYSQL DSN" HREF="ref.pdo-mysql.connection.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.mysql-unbuffered-query.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="ref.pdo-mysql.connection.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.pdo-mysql" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >XCIX. MySQL Functions (PDO_MYSQL)</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN136521" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pdo-mysql.intro" >简介</A ></H1 ><P > PDO_MYSQL is a driver that implements the <A HREF="ref.pdo.html" >PHP Data Objects (PDO) interface</A > to enable access from PHP to MySQL 3.x, 4.x and 5.x databases. </P ><P > PDO_MYSQL will take advantage of native prepared statement support present in MySQL 4.1 and higher. If you're using an older version of the mysql client libraries, PDO will emulate them for you. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >警告</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > Beware: Some MySQL table types (storage engines) do not support transactions. When writing transactional database code using a table type that does not support transactions, MySQL will pretend that a transaction was initiated successfully. In addition, any DDL queries issued will implicitly commit any pending transactions. </P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pdo-mysql.constants" >预定义常量</A ></H1 ><P >以下常量由本驱动程序所定义,并且仅在该扩展库被编译入 PHP 或在运行时动态加载时可用。此外,这些驱动程序特定的常量应仅在使用此驱动程序时被使用。在 Postgres 驱动下使用 MySQL 特定的属性可能会导致不可预期的行为。在代码可以运行于多个驱动程序下时,可以用 <B CLASS="function" >PDO::getAttribute()</B > 来取得 <TT CLASS="constant" ><B >PDO_ATTR_DRIVER_NAME</B ></TT > 属性以检查驱动程序。</P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >PDO::MYSQL_ATTR_USE_BUFFERED_QUERY</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > If this attribute is set to <TT CLASS="constant" ><B >TRUE</B ></TT > on a <B CLASS="classname" >PDOStatement</B >, the MySQL driver will use the buffered versions of the MySQL API. If you're writing portable code, you should use <B CLASS="function" >PDOStatement::fetchAll()</B > instead. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN136545" ></A ><P ><B >例 1. Forcing queries to be buffered in mysql</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">if (</font><font color="#0000BB">$db</font><font color="#007700">-></font><font color="#0000BB">getAttribute</font><font color="#007700">(</font><font color="#0000BB">PDO</font><font color="#007700">::</font><font color="#0000BB">ATTR_DRIVER_NAME</font><font color="#007700">) == </font><font color="#DD0000">'mysql'</font><font color="#007700">) {<br /> </font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">$db</font><font color="#007700">-></font><font color="#0000BB">prepare</font><font color="#007700">(</font><font color="#DD0000">'select * from foo'</font><font color="#007700">,<br /> array(</font><font color="#0000BB">PDO</font><font color="#007700">::</font><font color="#0000BB">MYSQL_ATTR_USE_BUFFERED_QUERY </font><font color="#007700">=> </font><font color="#0000BB">true</font><font color="#007700">));<br />} else {<br /> die(</font><font color="#DD0000">"my application only works with mysql; I should use \$stmt->fetchAll() instead"</font><font color="#007700">);<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DD ><DT ><TT CLASS="constant" ><B >PDO::MYSQL_ATTR_LOCAL_INFILE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > Enable <TT CLASS="literal" >LOAD LOCAL INFILE</TT >. </P ></DD ><DT ><TT CLASS="constant" ><B >PDO::MYSQL_ATTR_INIT_COMMAND</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > Command to execute when connecting to the MySQL server. Will automatically be re-executed when reconnecting. </P ></DD ><DT ><TT CLASS="constant" ><B >PDO::MYSQL_ATTR_READ_DEFAULT_FILE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > Read options from the named option file instead of from <TT CLASS="filename" >my.cnf</TT >. </P ></DD ><DT ><TT CLASS="constant" ><B >PDO::MYSQL_ATTR_READ_DEFAULT_GROUP</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > Read options from the named group from <TT CLASS="filename" >my.cnf</TT > or the file specified with <TT CLASS="constant" ><B >MYSQL_READ_DEFAULT_FILE</B ></TT >. </P ></DD ><DT ><TT CLASS="constant" ><B >PDO::MYSQL_ATTR_MAX_BUFFER_SIZE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > Maximum buffer size. Defaults to 1 MiB. </P ></DD ><DT ><TT CLASS="constant" ><B >PDO::MYSQL_ATTR_DIRECT_QUERY</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > Perform direct queries, don't use prepared statements. </P ></DD ></DL ></DIV ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >目录</B ></DT ><DT ><A HREF="ref.pdo-mysql.connection.html" >PDO_MYSQL DSN</A > -- Connecting to MySQL databases</DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.mysql-unbuffered-query.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="ref.pdo-mysql.connection.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >mysql_unbuffered_query</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >PDO_MYSQL DSN</TD ></TR ></TABLE ></DIV ></BODY ></HTML >