cvs: phpdoc /en/reference/mysqli mysqlnd.xml

From: Date: Wed, 11 Feb 2009 16:52:44 +0000
Subject: cvs: phpdoc /en/reference/mysqli mysqlnd.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-3203@lists.php.net to get a copy of this message
abedford Wed Feb 11 16:52:44 2009 UTC Added files: /phpdoc/en/reference/mysqli mysqlnd.xml Log: Initial draft of some MySQL Native Driver documentation. http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/mysqli/mysqlnd.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/mysqli/mysqlnd.xml +++ phpdoc/en/reference/mysqli/mysqlnd.xml <?xml version="1.0" encoding="utf-8"?> <!-- $Revision: 1.1 $ --> <chapter xml:id="mysqli.mysqlnd" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>The MySQL Native Driver</title> <para> This section of the manual provides an overview of the MySQL Native Driver. </para> <para> <emphasis role="bold">What is it?</emphasis> </para> <para> MySQL Native Driver is a replacement for the MySQL Client Library (libmysql). MySQL Native Driver is part of the official PHP 5.3 and PHP 6 branches. </para> <para> The MySQL database extensions MySQL extension, <literal>mysqli</literal> and PDO MYSQL all communicate with the MySQL server. In the past, this was done by the extension using the services provided by the MySQL Client Library. The extensions were compiled against the MySQL Client Library in order to use its client-server protocol. </para> <para> With MySQL Native Driver there is now an alternative, as the MySQL database extensions can be compiled to use MySQL Native Driver instead of the MySQL Client Library. </para> <para> MySQL Native Driver is written in C as a PHP extension. </para> <para> <emphasis role="bold">What it is not</emphasis> </para> <para> Although MySQL Native Driver is written as a PHP extension, it is important to note that it does not provide a new API to the PHP programmer. The programmer APIs for MySQL database connectivity are provided by the MySQL extension, <literal>mysqli</literal> and PDO MYSQL. These extensions can now use the services of MySQL Native Driver to communicate with the MySQL Server. Therefore, you should not think of MySQL Native Driver as an API. </para> <para> <emphasis role="bold">Why use it?</emphasis> </para> <para> Using the MySQL Native Driver offers a number of advantages over using the MySQL Client Library. </para> <para> The older MySQL Client Library was written by MySQL AB and so was released under the MySQL license. This ultimately led to MySQL support being disabled by default in PHP. However, the MySQL Native Driver has been developed as part of the PHP project, and is therefore released under the PHP license. This removes licensing issues that have been problematic in the past. </para> <para> Also, in the past, you needed to build the MySQL database extensions against a copy of the MySQL Client Library. This typically meant you needed to have MySQL installed on a machine where you were building the PHP source code. Also, when your PHP application was running, the MySQL database extensions would call down to the MySQL Client library file at run time, so the file needed to be installed on your system. With MySQL Native Driver that is no longer the case as it is included as part of the standard distribution. So you do not need MySQL installed in order to build PHP or run PHP database applications. </para> <para> Because MySQL Native Driver is written as a PHP extension, it is tightly coupled to the workings of PHP. This leads to gains in efficiency, especially when it comes to memory usage, as the driver uses the PHP memory management system. It also supports the PHP memory limit. Using MySQL Native Driver leads to comparable or better performance than using MySQL Client Library, it always ensures the most efficient use of memory. One example of the memory efficiency is the fact that when using the MySQL Client Library, each row is stored in memory twice, whereas with the MySQL Native Driver each row is only stored once in memory. </para> <para> <emphasis role="bold">Special features</emphasis> </para> <para> MySQL Native Driver also provides some special features not available when the MySQL database extensions use MySQL Client Library. These special features are listed below: </para> <itemizedlist> <listitem> <para> Improved persistent connections </para> </listitem> <listitem> <para> The special function <function>mysqli_fetch_all</function> </para> </listitem> <listitem> <para> Performance statistics calls: <literal>mysqli_get_cache_stats()</literal>, <literal>mysqli_get_client_stats()</literal>, <literal>mysqli_get_connection_stats()</literal> </para> </listitem> </itemizedlist> <para> The performance statistics facility can prove to be very useful in identifying performance bottlenecks. </para> <para> MySQL Native Driver also allows for persistent connections when used with the <literal>mysqli</literal> extension. </para> <para> <emphasis role="bold">Installation on Unix</emphasis> </para> <para> By default the MySQL database extensions are configured to use MySQL Client Library. In order to use the MySQL Native Driver, PHP needs to be built specifying that the MySQL database extensions are compiled with MySQL Native Driver support. This is done through configuration options prior to building the PHP source code. </para> <para> For example, to build the MySQL extension, <literal>mysqli</literal> and PDO MYSQL using the MySQL Native Driver, the following command would be given: </para> <programlisting role="shell">./configure --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ [other options]</programlisting> <para> <emphasis role="bold">Installation on Windows</emphasis> </para> <para> In the official PHP distributions from 5.3 onwards, MySQL Native Driver is enabled by default, so no additional configuration is required to use it. All MySQL database extensions will use MySQL Native Driver in this case. </para> <para> <emphasis role="bold">Using Persistent Connections</emphasis> </para> <para> The MySQL database extensions do not support persistent connections when used with the MySQL Client Library. However, they do when using MySQL Native Driver. When creating a connection the hostname is prepended with <quote>p:</quote>. This is demonstrated by the following code snippet, which creates a new connection using <literal>mysqli</literal>: </para> <programlisting role="php">$host="p:localhost"; $port=3306; $socket="/tmp/mysql.sock"; $user="root"; $password="password"; $dbname="test"; $conn = new mysqli($host, $user, $password, $dbname, $port, $socket) or die ('Could not connect to the database server' . mysqli_connect_error());</programlisting> <para> <emphasis role="bold">Using <function>mysqli_fetch_all</function></emphasis> </para> <para> If you are using <literal>mysqli</literal> with the MySQL Native Driver, you have access to the new API call <function>mysqli_fetch_all</function>. </para> <para> As <function>mysqli_fetch_all</function> returns all the rows as an array in a single step, it may consume more memory than some similar functions such as <function>mysqli_fetch_array</function>, which only returns one row at a time from the result set. Further, if you need to iterate over the result set, you will need a looping construct that will further impact performance. For these reasons <function>mysqli_fetch_all</function> should only be used in those situations where the fetched result set will be sent to another layer for processing. </para> <!-- Stats to do --> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->

« previous php.doc.cvs (#3203) next »