diff --git a/reference/mysqlinfo/concepts.xml b/reference/mysqlinfo/concepts.xml index 75339e9e95..11abdcb885 100644 --- a/reference/mysqlinfo/concepts.xml +++ b/reference/mysqlinfo/concepts.xml @@ -69,7 +69,6 @@ if ($uresult) { echo $row['Name'] . PHP_EOL; } } -$uresult->close(); ?> ]]> @@ -90,25 +89,6 @@ if ($uresult) { } } ?> -]]> - - - - - Unbuffered query example: mysql - - ]]> @@ -129,8 +109,7 @@ if ($uresult) { 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., mysqli_real_escape_string for mysqli, mysql_real_escape_string - for mysql, and PDO::quote for PDO_MySQL) will adhere to + (e.g., mysqli_real_escape_string for mysqli and PDO::quote 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'); - ?> ]]> @@ -183,16 +161,14 @@ $mysqli->set_charset('UTF-8'); 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"; ?> ]]> @@ -209,26 +185,6 @@ $pdo = new PDO("mysql:host=localhost;dbname=world;charset=utf8mb4", 'my_user', ' - - Setting the character set example: mysql - - -]]> - - diff --git a/reference/mysqlinfo/set.xml b/reference/mysqlinfo/set.xml index 03d7764949..7136414b90 100644 --- a/reference/mysqlinfo/set.xml +++ b/reference/mysqlinfo/set.xml @@ -25,12 +25,10 @@ Introduction - 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 mysql extension, - mysqli, or - PDO_MySQL. 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 + mysqli or + PDO_MySQL extensions. 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. @@ -134,11 +132,10 @@ - In the PHP documentation you will come across another term - + In the PHP documentation, you will come across another term - extension. The PHP code consists of a core, with optional extensions to the core functionality. PHP's - MySQL-related extensions, such as the mysqli - extension, and the mysql extension, are + MySQL-related extension, mysqli, is implemented using the PHP extension framework. @@ -165,15 +162,15 @@ Choosing an API - 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. - Comparing the three MySQL APIs + Comparing the MySQL APIs 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']); -?> ]]> - Recommended API + Feature comparison - It is recommended to use either the mysqli - or PDO_MySQL extensions. - It is not recommended to use the old mysql - 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%. - - Feature comparison - - + ext/mysqli PDO_MySQL - ext/mysql @@ -232,109 +212,86 @@ echo htmlentities($row['_message']); PHP version introduced 5.0 5.1 - 2.0 - Included with PHP 5.x + Included with PHP 7.x and 8.x Yes Yes - Yes - - - Included with PHP 7.x - Yes - Yes - No Development status Active Active - Maintenance only in 5.x; removed in 7.x Lifecycle Active Active - Deprecated in 5.x; removed in 7.x Recommended for new projects Yes Yes - No OOP Interface Yes Yes - No Procedural Interface Yes No - Yes API supports non-blocking, asynchronous queries with mysqlnd Yes No - No Persistent Connections Yes Yes - Yes API supports Charsets Yes Yes - Yes API supports server-side Prepared Statements Yes Yes - No API supports client-side Prepared Statements No Yes - No API supports Stored Procedures Yes Yes - No API supports Multiple Statements Yes Most - No API supports Transactions Yes Yes - No Transactions can be controlled with SQL Yes Yes - Yes Supports all MySQL 5.1+ functionality Yes Most - No @@ -344,13 +301,13 @@ echo htmlentities($row['_message']); Choosing a library - 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 mysqlnd library or the libmysqlclient library. Choosing a library is a compile time decision. - 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 mysqlnd documentation for @@ -362,13 +319,13 @@ echo htmlentities($row['_message']); @@ -417,28 +374,23 @@ $ ./configure --with-mysqli=/path/to/mysql_config --with-pdo-mysql=/path/to/mysq No end announced - PHP 5.4 and above; compile default (for all MySQL extensions) + Compile default (for all MySQL extensions) Yes No - - PHP 5.3; compile default (for all MySQL extensions) - No - Yes - Compression protocol support - Yes (5.3.1+) + Yes Yes SSL support - Yes (5.3.3+) + Yes Yes Named pipe support - Yes (5.3.4+) + Yes Yes