php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #81314 Add possibility to add MySQL Connection Attributes (incl. custom ones)
Submitted: 2021-07-30 16:00 UTC Modified: -
Votes:8
Avg. Score:4.2 ± 0.7
Reproduced:7 of 7 (100.0%)
Same Version:5 (71.4%)
Same OS:5 (71.4%)
From: andygrunwald at gmail dot com Assigned:
Status: Open Package: MySQLi related
PHP Version: 8.0.9 OS: -
Private report: No CVE-ID: None
 [2021-07-30 16:00 UTC] andygrunwald at gmail dot com
Description:
------------
MySQL offers to set Connection Attributes: See https://dev.mysql.com/doc/refman/8.0/en/performance-schema-connection-attribute-tables.html

Next to the reserved connection attributes (_client_name, ...), many applications set custom attributes, like `program_name`:

- mysqld: https://github.com/mysql/mysql-server/blob/3e90d07c3578e4da39dc1bce73559bbdf655c28c/sql/migrate_keyring.cc#L230
- ProxySQL: https://github.com/sysown/proxysql/pull/672/files
- mysqlcheck: https://github.com/mysql/mysql-server/blob/3e90d07c3578e4da39dc1bce73559bbdf655c28c/client/check/mysqlcheck.cc#L502
- mysqladmin: https://github.com/mysql/mysql-server/blob/beb865a960b9a8a16cf999c323e46c5b0c67f21f/client/mysqladmin.cc#L469
- and many more

Many programming languages, enable this feature via the DSN like Python  (https://dev.mysql.com/doc/dev/connector-python/8.0/tutorials/connection_attributes.html) or via setter functions like Java (http://mysqlblog.fivefarmers.com/2013/03/26/connection-attributes-in-mysql-5-6/).

PHP (mysqli or PDO) doesn't offer any kind of possibility to set a custom connection attribute like `program_name` .

With mysqli_options you can set options, but non of them are connection attributes, see https://www.php.net/manual/en/mysqli.options.php.
The mysqli constructor doesn't support DSNs, see https://www.php.net/manual/en/mysqli.construct.php

The PDO constructor does provide DSNs, see https://www.php.net/manual/de/pdo.construct.php.
But I can't see any possibilities for custom connection attributes from the user space.

mysqlnd does set already the _client_name attribute. See https://github.com/php/php-src/blob/132d49942460678908d47dc46b13a67b5e331677/ext/mysqlnd/mysqlnd_connection.c#L816

The goal of this feature request should be:
Create a way to set custom connection attributes during the connection to a MySQL server.


Patches

Pull Requests

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 07 20:01:27 2024 UTC