php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81658 mysql_option MYSQL_OPT_LOAD_DATA_LOCAL_DIR not available in mariadb libraries
Submitted: 2021-11-25 13:27 UTC Modified: 2021-11-26 11:53 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: yury at codescar dot eu Assigned:
Status: Closed Package: Compile Failure
PHP Version: 8.1.0 OS: Debian 10 (OS irrelevant)
Private report: No CVE-ID: None
 [2021-11-25 13:27 UTC] yury at codescar dot eu
Description:
------------
Compiling PHP 8.1.0 (https://www.php.net/distributions/php-8.1.0.tar.bz2) on Debian 10 with libmariadb packages (10.3.31 version) instead of mysqlnd, fails with error:

> /tmp/php-8.1.0/ext/mysqli/mysqli.c:600:59: error: 'MYSQL_OPT_LOAD_DATA_LOCAL_DIR' undeclared (first use in this function); did you mean 'MYSQL_OPT_READ_TIMEOUT'?
  REGISTER_LONG_CONSTANT("MYSQLI_OPT_LOAD_DATA_LOCAL_DIR", MYSQL_OPT_LOAD_DATA_LOCAL_DIR, CONST_CS | CONST_PERSISTENT);

This option was introduced in MySQL 8.0 (https://dev.mysql.com/doc/c-api/8.0/en/mysql-options.html) so there is a check in the previous line (https://github.com/php/php-src/blob/php-8.1.0/ext/mysqli/mysqli.c#L599)

> #if MYSQL_VERSION_ID >= 80021 || defined(MYSQLI_USE_MYSQLND)"

Unfortunately, it appears that with libmaria packages (10.3.31) `mysql_get_client_version()` returns a value of 100331 (as you can see from the compiling and running the test script).

Test script:
---------------
#include <stdlib.h>
#include <stdio.h>
#include <mysql.h>

int main(int argc, char **argv)
{
  printf("MySQL Client Version %lu\n", mysql_get_client_version());

  return EXIT_SUCCESS;
}

Compile: gcc -o testscript test.c `mysql_config --cflags --libs`
Execute: "MySQL Client Version 100331"

Expected result:
----------------
Being able to compile PHP 8.1.0 with MySQL extensions being compiled against the MariaDB Client Library


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-25 14:24 UTC] cmb@php.net
That versioning is a mess, but can't we just do

    #ifdef MYSQL_OPT_LOAD_DATA_LOCAL_DIR

here?
 [2021-11-26 05:49 UTC] yury at codescar dot eu
>>That versioning is a mess, but can't we just do
>>  #ifdef MYSQL_OPT_LOAD_DATA_LOCAL_DIR
>>here?

MYSQL_OPT_LOAD_DATA_LOCAL_DIR is defined as member of enum mysql_option (https://github.com/mysql/mysql-server/blob/3290a66c89eb1625a7058e0ef732432b6952b435/include/mysql.h#L213), so I think the preprocessor won't know anything about it.
 [2021-11-26 09:03 UTC] oliver at erply dot com
Having the same issue with only difference, building on CentOS.
 [2021-11-26 09:08 UTC] yury at codescar dot eu
-Operating System: Debian 10 +Operating System: Debian 10 (OS irrelevant) -PHP Version: 8.1.0RC6 +PHP Version: 8.1.0
 [2021-11-26 09:08 UTC] yury at codescar dot eu
Problem is OS irrelevant, it has to do with mariadb libraries
 [2021-11-26 11:53 UTC] cmb@php.net
> MYSQL_OPT_LOAD_DATA_LOCAL_DIR is defined as member of enum
> mysql_option […]

Ah, right, thanks!  Then we likely need something like:

    #if (MYSQL_VERSION_ID >= 80021 && !defined(MARIADB_BASE_VERSION)) || defined(MYSQLI_USE_MYSQLND)
 [2021-12-05 15:52 UTC] bugs dot php at osxtra dot dev
cmb@php.net's suggestion on 2021-11-26 @ 11:53 UTC seems to do the trick.

OS: OSX 10.15.7 (19H15)

Compiled app versions:
  Apache: 2.4.51
  PHP: 8.1.0
  MariaDB: 10.6.4

Editing these five lines in files located at php/8.1.0/ext/mysqli/ will allow the native MariaDB client to compile:

  mysqli.c:600
    Original: #if MYSQL_VERSION_ID >= 80021 || defined(MYSQLI_USE_MYSQLND)
    Modified: #if (MYSQL_VERSION_ID >= 80021 && !defined(MARIADB_BASE_VERSION)) || defined(MYSQLI_USE_MYSQLND)

  mysqli_api.c:1723
    Original: #if MYSQL_VERSION_ID >= 80021 || defined(MYSQLI_USE_MYSQLND)
    Modified: #if (MYSQL_VERSION_ID >= 80021 && !defined(MARIADB_BASE_VERSION)) || defined(MYSQLI_USE_MYSQLND)

  mysqli_driver.c:547
    Original: #if MYSQL_VERSION_ID >= 80021 || defined(PDO_USE_MYSQLND)
    Modified: #if (MYSQL_VERSION_ID >= 80021 && !defined(MARIADB_BASE_VERSION)) || defined(PDO_USE_MYSQLND)

  mysqli_driver.c:773
    Original: #if MYSQL_VERSION_ID >= 80021 || defined(PDO_USE_MYSQLND)
    Modified: #if (MYSQL_VERSION_ID >= 80021 && !defined(MARIADB_BASE_VERSION)) || defined(PDO_USE_MYSQLND)

  mysqli_nonapi.c:336
    Original: #if MYSQL_VERSION_ID >= 80021 || defined(MYSQLI_USE_MYSQLND)
    Modified: #if (MYSQL_VERSION_ID >= 80021 && !defined(MARIADB_BASE_VERSION)) || defined(MYSQLI_USE_MYSQLND)

With original code, php -i reports:
Client API library version => mysqlnd 8.1.0
Client API version => mysqlnd 8.1.0

With edited code, php -i reports:
Client API library version => 3.2.4
Client API header version => 10.6.4-MariaDB
 [2021-12-05 18:12 UTC] git@php.net
Automatic comment on behalf of devnexen (author) and cmb69 (committer)
Revision: https://github.com/php/php-src/commit/15e7e570a52795a6fea4af8d02f04567320d802f
Log: Fix #81658: MYSQL_OPT_LOAD_DATA_LOCAL_DIR not available in MariaDB
 [2021-12-05 18:12 UTC] git@php.net
-Status: Open +Status: Closed
 [2021-12-05 18:25 UTC] php dot bugs at osxtra dot dev
Oh, forgot to mention that in configure, --with-mysqli needed the path to mysql_config, and --with-pdo-mysql needed the base path to the MariaDB installation, otherwise the native mysqlnd library will be used by default.

Without the paths added to --with-mysqli and --with-pdo-mysql, both mysqli and mysqlnd will show up in php -i, both showing the native version.

With the paths, the compiled MariaDB/MySQL version showing in mysqli, but you won't see mysqlnd unless --enable-mysqlnd is also set.

It's unclear whether the external MariaDB/MySQL or native mysqlnd library will be used if both are present.

Without --with-mysqli or --with-pdo-mysql, you'll need sqlite in PKG_CONFIG_PATH or compilation will fail as no SQL driver will be available.

If your db server socket is in a non-standard location, you'll also need --with-mysql-sock=/path/to/socket, as well as pdo_mysql.default_socket=/path/to/socket in your php.ini  (configure has no provision for setting the socket when PDO is used)
 [2021-12-15 19:16 UTC] yury at codescar dot eu
Great, thank you very much for this fix :)
 [2021-12-28 07:45 UTC] oliver at erply dot com
Is there going to be fix here or I have to manually edit the lines at php/8.1.0/ext/mysqli/ ?
 [2022-02-19 21:50 UTC] bugs dot php at osxtra dot dev
Looks like the code has been patched, so for now, no need to manually edit with version changes.

v8.1.3 compiles without error whether the native driver or compiled MariaDB driver is used.

Yury's test script now returns "MySQL Client Version 30206", though the code references still appear to be comparing to 80021:

Machine [~/src/php/8.1.3/ext/mysqli] grep "80021" *
mysqli.c:#if (MYSQL_VERSION_ID >= 80021 && !defined(MARIADB_BASE_VERSION)) || defined(MYSQLI_USE_MYSQLND)
mysqli_api.c:#if (MYSQL_VERSION_ID >= 80021 && !defined(MARIADB_BASE_VERSION)) || defined(MYSQLI_USE_MYSQLND)
mysqli_nonapi.c:#if (MYSQL_VERSION_ID >= 80021 && !defined(MARIADB_BASE_VERSION)) || defined(MYSQLI_USE_MYSQLND)

Machine [~/src/php/8.1.3/ext/pdo_mysql] grep "80021" *
mysql_driver.c:#if (MYSQL_VERSION_ID >= 80021 && !defined(MARIADB_BASE_VERSION)) || defined(PDO_USE_MYSQLND)
mysql_driver.c:#if (MYSQL_VERSION_ID >= 80021 && !defined(MARIADB_BASE_VERSION)) || defined(PDO_USE_MYSQLND)
pdo_mysql.c:#if MYSQL_VERSION_ID >= 80021 || defined(PDO_USE_MYSQLND)
php_pdo_mysql_int.h:#if MYSQL_VERSION_ID >= 80021 || defined(PDO_USE_MYSQLND)

One last note, in my original post, mysqli_driver was actually mysql_driver in ext/pdo_mysql, not ext/mysqli.  Apologies for any confusion.

PHP 8.1.3 compiled against MariaDB 10.7.3:

# Using Native Driver
Client API library version => mysqlnd 8.1.3
Client API version => mysqlnd 8.1.3
Soap Client => enabled

# Using MariaDB
Client API library version => 3.2.6
Client API header version => 10.7.3-MariaDB
Client API version => 3.2.6
Soap Client => enabled
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed May 25 01:05:44 2022 UTC