Database is returning strings from integer columns
Posted: 05 June 2020, 22:51
Hello, starting today I've noticed a weird behaviour that I haven't seen before. I can't say for sure it's new, but the fact that I've noticed it twice today suggests something may have changed in Studio recently.
When I query the database it is returning strings for columns that are int type. I've observed this in my own custom table with getCollectionFromDb(), and in the `global` table used by getGameStateValue(). In both cases I was able to resolve the problem by casting to int in PHP, but it seems like I shouldn't have to.
Has anyone else noticed this?
Here's the table definition in case it helps:
And the PHP:
When I query the database it is returning strings for columns that are int type. I've observed this in my own custom table with getCollectionFromDb(), and in the `global` table used by getGameStateValue(). In both cases I was able to resolve the problem by casting to int in PHP, but it seems like I shouldn't have to.
Has anyone else noticed this?
Here's the table definition in case it helps:
Code: Select all
CREATE TABLE IF NOT EXISTS `gold_zone` (
`slot_num` INT UNSIGNED NOT NULL,
`gold` INT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`slot_num`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;Code: Select all
function getAllGoldOnTable()
{
$sql = "SELECT slot_num, gold FROM gold_zone";
return self::getCollectionFromDb($sql);
}
foreach ($this->getAllGoldOnTable() as $slot_num => $gold_zone)
{
$gold = (int)$gold_zone['gold']; <-- this is a string