How to update PDO setAttribute within Laravel Eloquent model?

Question

It turns out that in PHP 7.0 and up we have to manually configure PDO to not return the binary version of GUID. To implement the new PDO feature, I added setAttribue to my connection as shown:

    $connection = DB::connection('remoteRecipes');
    $php7GUIDHelper = defined('\PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER');
    if ($php7GUIDHelper):
        $connection->getPdo()->setAttribute(\PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER, true);
    endif;

    return $connection->table('Recipe')...

This resolved my GUID issue. However, the same does not work for models. I tried the following:

    $attributeModel = AttributeOptionsMap::where('apiId', $attribute);
    $php7GUIDHelper = defined('\PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER');
    if ($php7GUIDHelper):
        $attributeModel->getConnection()->getPdo()->setAttribute(\PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER, true);
    endif;
    $attributeModel = $attributeModel->first();

Should I attempt to manipulate the PDO parameter during the construction of the class? If so, how?


Show source
| pdo   | model   | eloquent   | laravel-5.2   2017-01-05 21:01 0 Answers

Answers to How to update PDO setAttribute within Laravel Eloquent model? ( 0 )

Leave a reply to - How to update PDO setAttribute within Laravel Eloquent model?

◀ Go back