rfc:improve_mysqli
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:improve_mysqli [2020/12/30 16:50] – created dharman | rfc:improve_mysqli [2020/12/30 18:27] (current) – Grammar dharman | ||
---|---|---|---|
Line 17: | Line 17: | ||
==== Exception error reporting mode should be the default one ==== | ==== Exception error reporting mode should be the default one ==== | ||
- | Why is error reporting disabled by default? The reasoning behind this was probably to hide very sensitive information present in the error messages on production systems that have '' | + | //Why is error reporting disabled by default?// The reasoning behind this was probably to hide very sensitive information present in the error messages on production systems that have '' |
Since PHP 8.0 PDO has exception mode enabled by default, it would only make sense to do the same for mysqli. [[rfc:: | Since PHP 8.0 PDO has exception mode enabled by default, it would only make sense to do the same for mysqli. [[rfc:: | ||
Line 41: | Line 41: | ||
Let's break this point into smaller issues. At the moment we have at least 4 ways of opening a connection to the MySQL server and at least 2 ways of initializing mysqli object without connecting. Each one is slightly different than the other. | Let's break this point into smaller issues. At the moment we have at least 4 ways of opening a connection to the MySQL server and at least 2 ways of initializing mysqli object without connecting. Each one is slightly different than the other. | ||
- | === mysqli:: | + | === mysqli:: |
- | Despite what the documentation says, '' | + | Despite what the documentation says, '' |
The only valid use case for this method was in polymorphism, | The only valid use case for this method was in polymorphism, | ||
Line 63: | Line 63: | ||
=== "new mysqli()" | === "new mysqli()" | ||
- | At the moment PHP manual claims that all 6 parameters of '' | + | At the moment PHP manual claims that all 6 parameters of '' |
<code php> | <code php> | ||
Line 77: | Line 77: | ||
</ | </ | ||
+ | |||
+ | === '' | ||
+ | The [[https:// | ||
+ | |||
+ | 1. '' | ||
+ | > Returns an object which represents the connection to a MySQL Server, or false on failure. | ||
+ | The signature for '' | ||
+ | <code PHP> | ||
+ | $mysqli = new mysqli(' | ||
+ | </ | ||
+ | |||
+ | 2. You can call '' | ||
+ | |||
+ | 3. The whole notion of functional //aliases// for constructors is quite strange. They might be equivalent in functionality, | ||
+ | <code php> | ||
+ | class my_mysqli extends \mysqli{ | ||
+ | public function __construct() { | ||
+ | // the only possible way to connect is to call '' | ||
+ | parent:: | ||
+ | // or trigger parent constructor followed by '' | ||
+ | parent:: | ||
+ | parent:: | ||
+ | // (technically it can also be '' | ||
+ | // It can even be this monster: | ||
+ | [$this, \connect:: | ||
+ | // but there is no way to call '' | ||
+ | mysqli_connect(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $mysqli = new my_mysqli(); | ||
+ | </ | ||
+ | Constructors cannot have functional aliases in a true sense as 1 to 1 replacements. '' | ||
+ | <code php> | ||
+ | function mysqli_connect(/ | ||
+ | $mysqli = mysqli_init(); | ||
+ | if ($mysqli-> | ||
+ | return $mysqli; | ||
+ | } else { | ||
+ | return false; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | The documentation should be improved and stop calling the function and the constructor as aliases. | ||
+ | |||
+ | === mysqli_init() and mysqli_real_connect() are weird aliases that do not match OO style. === | ||
+ | |||
+ | '' | ||
+ | <code php> | ||
+ | $mysqli = mysqli_init(); | ||
+ | $mysqli = new mysqli(); | ||
+ | </ | ||
+ | |||
+ | '' | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | Given that all functions are very similar you can also mix & match as long as you don't need that 7th parameter. For example. | ||
+ | <code php> | ||
+ | // 1. new mysqli and real_connect | ||
+ | $mysqli = new mysqli(); | ||
+ | $mysqli-> | ||
+ | |||
+ | // 2. mysqli_init and connect | ||
+ | $mysqli = mysqli_init(); | ||
+ | $mysqli-> | ||
+ | </ | ||
+ | |||
+ | === Proposal === | ||
+ | |||
+ | These functions need some refactoring. I see no reason to have so many confusing functions with tiny differences. It makes both implementation and documentation unnecessarily complicated and it does not help users make the right decisions and avoid mistakes. | ||
+ | |||
+ | - Make '' | ||
+ | - Remove '' | ||
+ | - CMB69 has suggested that it should be a static function, but I find it revolting to have a static method as an alias of the constructor for absolutely no reason. After all, we have the OO-style equivalent already: the constructor. | ||
+ | - Align the behaviour of '' | ||
+ | - We could either keep '' | ||
+ | // 1. initialize object | ||
+ | $mysqli = mysqli_connect(); | ||
+ | // 2. set options | ||
+ | mysqli_options($mysqli, | ||
+ | // 3. connect | ||
+ | mysqli_real_connect($mysqli); | ||
+ | </ | ||
+ | - We should optionally deprecate and remove '' | ||
+ | |||
+ | I realize that the whole mess comes from the fact that we try to maintain both OO and procedural style. My proposal therefore is aimed to keep the two ways of opening the connection as clear as possible reducing inconsistencies and confusion. The below examples should respectively be the recommended way for opening and setting connection options with OO and procedural style: | ||
+ | |||
+ | <code php> | ||
+ | // OOP | ||
+ | $mysqli = new mysqli(); // <- 0 arguments | ||
+ | $mysqli-> | ||
+ | $mysqli-> | ||
+ | |||
+ | // Procedural | ||
+ | $mysqli = mysqli_init(); | ||
+ | mysqli_options($mysqli, | ||
+ | mysqli_real_connect($mysqli, | ||
+ | </ | ||
+ | |||
+ | The shorthand form without setting options would stay as it is now. However, we would have to split the documentation for '' | ||
+ | |||
+ | ==== libmysqlclient support - untested and unmaitained ==== | ||
+ | |||
+ | PHP has been pushing for the use of mysqlnd for years. While it is still possible to compile PHP against libmysql client, and Nikita has spent some time fixing the support, the truth is that the libmysql support has been in decline ever since mysqlnd was released. The native driver offers more and often better. We have the full control of mysqlnd and its implementation including fixing bugs, memory handling, adding new features and error reporting. As of now, de jure compatibility makes fixing some stuff in mysqlnd more limited and difficult. | ||
+ | |||
+ | We should consider dropping the support for libmysql client in the near future. It would make maintenance of the mysqli extension easier, considering the number of people willing and capable of actively maintaining it. | ||
+ | |||
+ | ==== The never-finished features ==== | ||
+ | |||
+ | I include this section for completeness but as of now I have no clue what should be done about them and how to improve these functionalities. | ||
+ | |||
+ | === mysqli:: | ||
+ | |||
+ | The functionality works as is. Nikita has recently removed the part of the code that was never finished. While the functionality never actually got finished, the way it works now is fine as is. | ||
+ | |||
+ | === mysqli:: | ||
+ | |||
+ | As far as I know, these two methods don't actually do anything useful. I suppose the idea was to abstract some SQL functionality but given that the function name is the same as the actual SQL command I really don't see the point. The development should be ironed out, or the functionality should be deprecated and removed. | ||
+ | |||
+ | === Async queries === | ||
+ | |||
+ | I believe this functionality mostly works. At least the example given in PHP manual works, albeit I have a lot of questions about that example. It seems this is only available for mysqlnd and only for normal queries. Prepared statements are not supported. I assume this is meant to aid in running parallel queries on multiple mysqli connections, | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | What breaks, | + | |
+ | * Existing code that does not explicitly set the mysqli error mode and relies on the silent mode will be affected by this change. This code can be updated by explicitly setting the mysqli error mode to silent. e.g. <code PHP> | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | Optional: | ||
+ | |||
+ | * Aliases '' | ||
+ | * '' | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | List the proposed PHP versions that the feature will be included in. Use relative versions such as "next PHP 8.x" or "next PHP 8.x.y". | + | Most changes should go into next PHP 8.x, but some of the described changes can only be made in the next PHP x |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
==== To SAPIs ==== | ==== To SAPIs ==== | ||
- | Describe the impact to CLI, Development web server, embedded PHP etc. | + | N/A |
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
- | Will existing extensions | + | If we are going to drop support for libmysql client in mysqli then this should |
==== To Opcache ==== | ==== To Opcache ==== | ||
- | It is necessary to develop RFC's with opcache in mind, since opcache is a core extension distributed with PHP. | + | N/A |
- | + | ||
- | Please explain how you have verified your RFC's compatibility with opcache. | + | |
==== New Constants ==== | ==== New Constants ==== | ||
- | Describe any new constants so they can be accurately and comprehensively explained in the PHP documentation. | + | N/A |
==== php.ini Defaults ==== | ==== php.ini Defaults ==== | ||
- | If there are any php.ini settings then list: | + | N/A |
- | * hardcoded default values | + | |
- | * php.ini-development values | + | |
- | * php.ini-production values | + | |
===== Open Issues ===== | ===== Open Issues ===== | ||
- | Make sure there are no open issues when the vote starts! | ||
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
- | List existing areas/ | ||
- | This helps avoid any ambiguity, shows that you have thought deeply about the RFC' | + | The signature of certain mysqli functions/ |
- | ===== Future Scope ===== | + | - '' |
- | This section details areas where the feature might be improved in future, but that are not currently proposed in this RFC. | + | - '' |
- | ===== Proposed Voting Choices ===== | + | The existing prepared statement parameter binding will remain unaffected. There will be no change to '' |
- | Include these so readers know where you are heading and can discuss the proposed voting options. | + | |
- | ===== Patches and Tests ===== | + | The existing procedural style connection will remain the same. The only potential difference would be that '' |
- | Links to any external patches and tests go here. | + | |
- | If there is no patch, make it clear who will create a patch, or whether a volunteer to help with implementation is needed. | + | Opening the connection while setting options before |
- | Make it clear if the patch is intended to be the final patch, or is just a prototype. | + | ===== Future Scope ===== |
- | For changes affecting | + | ===== Proposed Voting Choices ===== |
+ | The RFC is just a concept at the moment. For voting purposes, the details will need to be ironed out and each proposal voted on separately. | ||
+ | |||
+ | ===== Patches and Tests ===== | ||
+ | I will try to create patches | ||
===== Implementation ===== | ===== Implementation ===== | ||
- | After the project is implemented, | + | N/A |
- | - the version(s) it was merged into | + | |
- | - a link to the git commit(s) | + | |
- | - a link to the PHP manual entry for the feature | + | |
- | - a link to the language specification section (if any) | + | |
===== References ===== | ===== References ===== | ||
- | Links to external references, discussions or RFCs | + | N/A |
===== Rejected Features ===== | ===== Rejected Features ===== | ||
- | Keep this updated with features that were discussed on the mail lists. | + | N/A |
rfc/improve_mysqli.1609347028.txt.gz · Last modified: 2020/12/30 16:50 by dharman