mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Remove references to mysql
extension and to versions below 7.0
Closes GH-315.
This commit is contained in:
parent
cc422ba8c7
commit
383a659e1f
2 changed files with 27 additions and 119 deletions
|
@ -69,7 +69,6 @@ if ($uresult) {
|
|||
echo $row['Name'] . PHP_EOL;
|
||||
}
|
||||
}
|
||||
$uresult->close();
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -90,25 +89,6 @@ if ($uresult) {
|
|||
}
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>Unbuffered query example: mysql</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$conn = mysql_connect("localhost", "my_user", "my_pass");
|
||||
$db = mysql_select_db("world");
|
||||
|
||||
$uresult = mysql_unbuffered_query("SELECT Name FROM City");
|
||||
if ($uresult) {
|
||||
while ($row = mysql_fetch_assoc($uresult)) {
|
||||
echo $row['Name'] . PHP_EOL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -129,8 +109,7 @@ if ($uresult) {
|
|||
<para>
|
||||
The character set should be understood and defined, as it has an affect on every
|
||||
action, and includes security implications. For example, the escaping mechanism
|
||||
(e.g., <function>mysqli_real_escape_string</function> for mysqli, <function>mysql_real_escape_string</function>
|
||||
for mysql, and <methodname>PDO::quote</methodname> for PDO_MySQL) will adhere to
|
||||
(e.g., <function>mysqli_real_escape_string</function> for mysqli and <methodname>PDO::quote</methodname> for PDO_MySQL) will adhere to
|
||||
this setting. It is important to realize that these functions will not use the character
|
||||
set that is defined with a query, so for example the following will not have an effect
|
||||
on them:
|
||||
|
@ -156,7 +135,6 @@ $mysqli->set_charset('utf8mb4');
|
|||
|
||||
// But, this will NOT affect it (UTF-8 vs utf8mb4) -- don't use dashes here
|
||||
$mysqli->set_charset('UTF-8');
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -183,16 +161,14 @@ $mysqli->set_charset('UTF-8');
|
|||
<?php
|
||||
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
|
||||
|
||||
printf("Initial character set: %s\n", $mysqli->character_set_name());
|
||||
echo 'Initial character set: ' . $mysqli->character_set_name() . "\n";
|
||||
|
||||
if (!$mysqli->set_charset('utf8mb4')) {
|
||||
printf("Error loading character set utf8mb4: %s\n", $mysqli->error);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo "New character set information:\n";
|
||||
print_r( $mysqli->get_charset() );
|
||||
|
||||
echo 'Your current character set is: ' . $mysqli->character_set_name() . "\n";
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -209,26 +185,6 @@ $pdo = new PDO("mysql:host=localhost;dbname=world;charset=utf8mb4", 'my_user', '
|
|||
</programlisting>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>Setting the character set example: mysql</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$conn = mysql_connect("localhost", "my_user", "my_pass");
|
||||
$db = mysql_select_db("world");
|
||||
|
||||
echo 'Initial character set: ' . mysql_client_encoding($conn) . "\n";
|
||||
|
||||
if (!mysql_set_charset('utf8mb4', $conn)) {
|
||||
echo "Error: Unable to set the character set.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
echo 'Your current character set is: ' . mysql_client_encoding($conn);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
|
|
|
@ -25,12 +25,10 @@
|
|||
<title>Introduction</title>
|
||||
<abstract>
|
||||
<para>
|
||||
Depending on the version of PHP, there are either two or three PHP APIs
|
||||
for accessing the MySQL database. PHP 5 users can choose between the
|
||||
deprecated <link linkend="book.mysql">mysql</link> extension,
|
||||
<link linkend="book.mysqli">mysqli</link>, or
|
||||
<link linkend="ref.pdo-mysql">PDO_MySQL</link>. PHP 7 removes the mysql
|
||||
extension, leaving only the latter two options.
|
||||
There are several PHP APIs
|
||||
for accessing the MySQL database. Users can choose between the
|
||||
<link linkend="book.mysqli">mysqli</link> or
|
||||
<link linkend="ref.pdo-mysql">PDO_MySQL</link> extensions.
|
||||
</para>
|
||||
<para>
|
||||
This guide explains the
|
||||
|
@ -68,7 +66,7 @@
|
|||
APIs can be procedural or object-oriented. With a procedural API you
|
||||
call functions to carry out tasks, with the object-oriented API you
|
||||
instantiate classes and then call methods on the resulting objects.
|
||||
Of the two the latter is usually the preferred interface, as it is
|
||||
Of the two, the latter is usually the preferred interface, as it is
|
||||
more modern and leads to better organized code.
|
||||
</para>
|
||||
|
||||
|
@ -134,11 +132,10 @@
|
|||
</para>
|
||||
|
||||
<para>
|
||||
In the PHP documentation you will come across another term -
|
||||
In the PHP documentation, you will come across another term -
|
||||
<emphasis>extension</emphasis>. The PHP code consists of a core,
|
||||
with optional extensions to the core functionality. PHP's
|
||||
MySQL-related extensions, such as the <literal>mysqli</literal>
|
||||
extension, and the <literal>mysql</literal> extension, are
|
||||
MySQL-related extension, <literal>mysqli</literal>, is
|
||||
implemented using the PHP extension framework.
|
||||
</para>
|
||||
|
||||
|
@ -165,15 +162,15 @@
|
|||
<chapter xml:id="mysqlinfo.api.choosing" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Choosing an API</title>
|
||||
<para>
|
||||
PHP offers three different APIs to connect to MySQL. Below we show
|
||||
the APIs provided by the mysql, mysqli, and PDO extensions. Each code snippet
|
||||
PHP offers different APIs to connect to MySQL. Below we show
|
||||
the APIs provided by the mysqli and PDO extensions. Each code snippet
|
||||
creates a connection to a MySQL server running on "example.com" using
|
||||
the username "user" and the password "password". And a query is run to
|
||||
greet the user.
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Comparing the three MySQL APIs</title>
|
||||
<title>Comparing the MySQL APIs</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
@ -188,43 +185,26 @@ $pdo = new PDO('mysql:host=example.com;dbname=database', 'user', 'password');
|
|||
$statement = $pdo->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
|
||||
$row = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
echo htmlentities($row['_message']);
|
||||
|
||||
// mysql
|
||||
$c = mysql_connect("example.com", "user", "password");
|
||||
mysql_select_db("database");
|
||||
$result = mysql_query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
|
||||
$row = mysql_fetch_assoc($result);
|
||||
echo htmlentities($row['_message']);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<emphasis role="bold">Recommended API</emphasis>
|
||||
<emphasis role="bold">Feature comparison</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
It is recommended to use either the <link linkend="book.mysqli">mysqli</link>
|
||||
or <link linkend="ref.pdo-mysql">PDO_MySQL</link> extensions.
|
||||
It is not recommended to use the old <link linkend="ref.mysql">mysql</link>
|
||||
extension for new development, as it was deprecated in PHP 5.5.0 and was
|
||||
removed in PHP 7. A detailed feature comparison matrix is provided below.
|
||||
The overall performance of all three extensions is considered to be about
|
||||
The overall performance of both extensions is considered to be about
|
||||
the same. Although the performance of the extension contributes only a
|
||||
fraction of the total run time of a PHP web request. Often, the impact is
|
||||
as low as 0.1%.
|
||||
</para>
|
||||
<para>
|
||||
<emphasis role="bold">Feature comparison</emphasis>
|
||||
</para>
|
||||
<informaltable>
|
||||
<tgroup cols="4">
|
||||
<tgroup cols="3">
|
||||
<thead>
|
||||
<row>
|
||||
<entry></entry>
|
||||
<entry>ext/mysqli</entry>
|
||||
<entry>PDO_MySQL</entry>
|
||||
<entry>ext/mysql</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -232,109 +212,86 @@ echo htmlentities($row['_message']);
|
|||
<entry>PHP version introduced</entry>
|
||||
<entry>5.0</entry>
|
||||
<entry>5.1</entry>
|
||||
<entry>2.0</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Included with PHP 5.x</entry>
|
||||
<entry>Included with PHP 7.x and 8.x</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Included with PHP 7.x</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>No</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Development status</entry>
|
||||
<entry>Active</entry>
|
||||
<entry>Active</entry>
|
||||
<entry>Maintenance only in 5.x; removed in 7.x</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Lifecycle</entry>
|
||||
<entry>Active</entry>
|
||||
<entry>Active</entry>
|
||||
<entry>Deprecated in 5.x; removed in 7.x</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Recommended for new projects</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>No</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>OOP Interface</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>No</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Procedural Interface</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>No</entry>
|
||||
<entry>Yes</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>API supports non-blocking, asynchronous queries with mysqlnd</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>No</entry>
|
||||
<entry>No</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Persistent Connections</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>API supports Charsets</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>API supports server-side Prepared Statements</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>No</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>API supports client-side Prepared Statements</entry>
|
||||
<entry>No</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>No</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>API supports Stored Procedures</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>No</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>API supports Multiple Statements</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Most</entry>
|
||||
<entry>No</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>API supports Transactions</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>No</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Transactions can be controlled with SQL</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Supports all MySQL 5.1+ functionality</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Most</entry>
|
||||
<entry>No</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
|
@ -344,13 +301,13 @@ echo htmlentities($row['_message']);
|
|||
<chapter xml:id="mysqlinfo.library.choosing" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Choosing a library</title>
|
||||
<para>
|
||||
The mysqli, PDO_MySQL and mysql PHP extensions are lightweight wrappers on
|
||||
The mysqli and PDO_MySQL PHP extensions are lightweight wrappers on
|
||||
top of a C client library. The extensions can either use the
|
||||
<link linkend="book.mysqlnd">mysqlnd</link> library or the <literal>libmysqlclient</literal>
|
||||
library. Choosing a library is a compile time decision.
|
||||
</para>
|
||||
<para>
|
||||
The mysqlnd library is part of the PHP distribution since 5.3.0. It offers
|
||||
The mysqlnd library is part of the PHP distribution. It offers
|
||||
features like lazy connections and query caching, features that are not available
|
||||
with libmysqlclient, so using the built-in mysqlnd library is highly recommended.
|
||||
See the <link linkend="book.mysqlnd">mysqlnd documentation</link> for
|
||||
|
@ -362,13 +319,13 @@ echo htmlentities($row['_message']);
|
|||
<programlisting role="shell">
|
||||
<![CDATA[
|
||||
// Recommended, compiles with mysqlnd
|
||||
$ ./configure --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd
|
||||
$ ./configure --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
|
||||
|
||||
// Alternatively recommended, compiles with mysqlnd as of PHP 5.4
|
||||
$ ./configure --with-mysqli --with-pdo-mysql --with-mysql
|
||||
// Alternatively recommended, compiles with mysqlnd
|
||||
$ ./configure --with-mysqli --with-pdo-mysql
|
||||
|
||||
// Not recommended, compiles with libmysqlclient
|
||||
$ ./configure --with-mysqli=/path/to/mysql_config --with-pdo-mysql=/path/to/mysql_config --with-mysql=/path/to/mysql_config
|
||||
$ ./configure --with-mysqli=/path/to/mysql_config --with-pdo-mysql=/path/to/mysql_config
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -417,28 +374,23 @@ $ ./configure --with-mysqli=/path/to/mysql_config --with-pdo-mysql=/path/to/mysq
|
|||
<entry>No end announced</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>PHP 5.4 and above; compile default (for all MySQL extensions)</entry>
|
||||
<entry>Compile default (for all MySQL extensions)</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>No</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>PHP 5.3; compile default (for all MySQL extensions)</entry>
|
||||
<entry>No</entry>
|
||||
<entry>Yes</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Compression protocol support</entry>
|
||||
<entry>Yes (5.3.1+)</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>SSL support</entry>
|
||||
<entry>Yes (5.3.3+)</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Named pipe support</entry>
|
||||
<entry>Yes (5.3.4+)</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
</row>
|
||||
<row>
|
||||
|
|
Loading…
Reference in a new issue