MySQL integer field is returned as string in PHP
Use the mysqlnd (native driver) for php.
If you're on Ubuntu:
sudo apt-get install php5-mysqlndsudo service apache2 restart
If you're on Centos:
sudo yum install php-mysqlndsudo service httpd restart
The native driver returns integer types appropriately.
As @Jeroen has pointed out, this method will only work out-of-the-box for PDO.
As @LarsMoelleken has pointed out, this method will work with mysqli if you also set the MYSQLI_OPT_INT_AND_FLOAT_NATIVE option to true.
Example:
$mysqli->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, TRUE);