📄 ref.pdo-mysql.html
字号:
<!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 http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.pdo-informix.connection.html">PDO_INFORMIX DSN</a></div> <div class="next" style="text-align: right; float: right;"><a href="ref.pdo-mysql.connection.html">PDO_MYSQL DSN</a></div> <div class="up"><a href="pdo.drivers.html">PDO Drivers</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div> <h1 class="title">MySQL Functions (PDO_MYSQL)</h1> <div class="partintro"> <div id="pdo-mysql.intro" class="section"> <h2 class="title">Introduction</h2> <p class="para"> PDO_MYSQL is a driver that implements the <a href="intro.pdo.html" class="link">PHP Data Objects (PDO) interface</a> to enable access from PHP to MySQL 3.x, 4.x and 5.x databases. </p> <p class="para"> 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"><b class="warning">Warning</b> <p class="para"> 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> </div> </div> <div id="pdo-mysql.constants" class="section"> <h2 class="title">Predefined Constants</h2> <p class="simpara">The constants below are defined bythis driver, and will only be available when the extension has been eithercompiled into PHP or dynamically loaded at runtime. In addition, thesedriver-specific constants should only be used if you are using this driver.Using mysql-specific attributes with the postgres driver may result inunexpected behaviour. <a href="pdo.getattribute.html" class="function">PDO::getAttribute()</a> may be used toobtain the <b><tt>PDO_ATTR_DRIVER_NAME</tt></b> attribute to check thedriver, if your code can run against multiple drivers.</p> <dl> <dt> <span class="term"> <b><tt>PDO::MYSQL_ATTR_USE_BUFFERED_QUERY</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <span class="simpara"> If this attribute is set to <b><tt>TRUE</tt></b> on a <a href="class.pdostatement.html" class="classname">PDOStatement</a>, the MySQL driver will use the buffered versions of the MySQL API. If you're writing portable code, you should use <a href="pdostatement.fetchall.html" class="function">PDOStatement::fetchAll()</a> instead. </span> <p class="para"> <div class="example"><p><b>Example #1 Forcing queries to be buffered in mysql</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">getAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">ATTR_DRIVER_NAME</span><span style="color: #007700">) == </span><span style="color: #DD0000">'mysql'</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'select * from foo'</span><span style="color: #007700">,<br /> array(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">MYSQL_ATTR_USE_BUFFERED_QUERY </span><span style="color: #007700">=> </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />} else {<br /> die(</span><span style="color: #DD0000">"my application only works with mysql; I should use \$stmt->fetchAll() instead"</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </dd> </dt> <dt> <span class="term"> <b><tt>PDO::MYSQL_ATTR_LOCAL_INFILE</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <p class="para"> Enable <i>LOAD LOCAL INFILE</i>. </p> </dd> </dt> <dt> <span class="term"> <b><tt>PDO::MYSQL_ATTR_INIT_COMMAND</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <p class="para"> Command to execute when connecting to the MySQL server. Will automatically be re-executed when reconnecting. </p> </dd> </dt> <dt> <span class="term"> <b><tt>PDO::MYSQL_ATTR_READ_DEFAULT_FILE</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <p class="para"> Read options from the named option file instead of from <var class="filename">my.cnf</var>. </p> </dd> </dt> <dt> <span class="term"> <b><tt>PDO::MYSQL_ATTR_READ_DEFAULT_GROUP</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <p class="para"> Read options from the named group from <var class="filename">my.cnf</var> or the file specified with <b><tt>MYSQL_READ_DEFAULT_FILE</tt></b>. </p> </dd> </dt> <dt> <span class="term"> <b><tt>PDO::MYSQL_ATTR_MAX_BUFFER_SIZE</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <p class="para"> Maximum buffer size. Defaults to 1 MiB. </p> </dd> </dt> <dt> <span class="term"> <b><tt>PDO::MYSQL_ATTR_DIRECT_QUERY</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <p class="para"> Perform direct queries, don't use prepared statements. </p> </dd> </dt> </dl></div> </div> <h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="ref.pdo-mysql.connection.html">PDO_MYSQL DSN</a> 鈥
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -