derdida derdida - 1 year ago 365
PHP Question

Laravel PDO Settings?

I would like to return integers als integers from my database. At the moment all values would be loaded as Strings. Database is MSSQL 2012 and ill use the PDO driver (for v5.6).

Trying to set the properties here: (as shown here, but i dont know if thats still possible:

'sqlsrv' => [
'driver' => 'sqlsrv',
'charset' => 'utf8',
'prefix' => '',
'options' => array(

But still always getting an error:

SQLSTATE[IMSSP]: The given attribute is only supported on the PDOStatement object.

How can i set any settings for the PDO Driver? So to return Integers als Integers, and not as Strings.

This is still not working:

$pdo = DB::connection()->getPdo();
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
.. do ORM Query

Bringing the same error.

Maybe anyone can help me?

Answer Source

I believe this issue is related to the PDO driver used (thats installed with PHP, not laravel configuration).

Not quite what you're looking for but could potentially solve your problems. Since laravel 5 theres been a casts feature on eloquent where your columns are automatically cast to your pre-defined types. See

// Eloquent Model
protected $casts = [
    'int_column'   => 'int',

Your int_column would then automatically be cast to an int when the model is retrieved from the database

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download