简体   繁体   中英

PHP7 PDO_DBLIB uniqueidentifier

I'm currently using the pdo_dblib extension in my project. When I use this under PHP 5.6 with FreeTDS Version 7.0 set in config. It will give me the uniqueidentifier as string . When i use the same script under PHP 7.0.8 it just gives me out some garbled shit. I don't wanna cast it in the SQL or convert it later in PHP . Because sometimes it can be a uniqueidentifier in the result and sometimes not. so i would need to go through the complete results to convert the uniqueidentifier.

So is there any solution to get in work on PHP 7.0.8 like it was under PHP 5.6 ?

As explained in the pull request mentioned in Bojan's answer, the cause of this issue in PHP 7 is that you have to instruct PDO to convert the GUIDs from binary to a string.

This should do it for anyone struggling with this.

    /** @var \PDO $pdo */
    $pdo->setAttribute(\PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER, true);

It looks like the bug was introduced in some minor version of PHP7.

  • 7.0.4 works perfectly. You can manually compile it with phpbrew.
  • 7.0.8 has this implementation currently broken.

There was already a bug report filed for this issue here: https://bugs.php.net/bug.php?id=72601

and a pull request for a potential fix: https://github.com/php/php-src/pull/2001

Add the following flag to your \\PDO instance

/** @var \PDO $pdo */
$pdo->setAttribute(\PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM