framework icon indicating copy to clipboard operation
framework copied to clipboard

Queries to DB return string instead of defined type

Open kazimirchuk opened this issue 10 years ago • 0 comments

I have a table UsersCars where I store: "user_id", "car_id" and "airbags". "car_id" and "airbags" are int columns, but when I try to get needed rows from a table, I get them as strings. Specifically I'm using:

$select = UsersCars\Table::select();
$select->select('car_id as carId, airbags')->where('user_id = ?', $userId);
return $select->execute();

It returns me:

array (size=1)
  0 => 
    object(Application\Garage\UsersCars\Row)[36]
      protected 'data' => 
        array (size=2)
          'carId' => string "3"
          'airbags' => string "8"

The problem is that I need carId and airbags as integers but I'm getting strings. Surfing over the Internet I found the reason of such a strange behaviour. It is in an installed php5-mysql driver. To solve this problem I removed it and then installed php5-mysqlnd. Also I added this to an application.config:

"db" => [
    "connect" => [
        "options" => [
            \PDO::ATTR_EMULATE_PREPARES => false
        ...
        ]
    ]
]

Maybe it will help somebody.

kazimirchuk avatar Feb 10 '15 16:02 kazimirchuk