mysql_query_attribute_string(
name
)Applications can define attributes that apply to the next query sent to the server. The
mysql_query_attribute_string()
function, available as of MySQL 8.0.23, returns an attribute value as a string, given the attribute name. This function enables a query to access and incorporate values of the attributes that apply to it.mysql_query_attribute_string()
is installed by installing thequery_attributes
component. See Section 9.6, “Query Attributes”, which also discusses the purpose and use of query attributes.Arguments:
name
: The attribute name.
Return value:
Returns the attribute value as a string for success, or
NULL
if the attribute does not exist.Example:
The following example uses the mysql client
query_attributes
command to define query attributes that can be retrieved bymysql_query_attribute_string()
. TheSELECT
shows that retrieving a nonexistent attribute (n3
) returnsNULL
.mysql> query_attributes n1 v1 n2 v2; mysql> SELECT -> mysql_query_attribute_string('n1') AS 'attr 1', -> mysql_query_attribute_string('n2') AS 'attr 2', -> mysql_query_attribute_string('n3') AS 'attr 3'; +--------+--------+--------+ | attr 1 | attr 2 | attr 3 | +--------+--------+--------+ | v1 | v2 | NULL | +--------+--------+--------+
For additional examples, see Section 9.6, “Query Attributes”.