如何从MySQL中获取一个整数作为PHP中的整数? [英] How to get an integer from MySQL as integer in PHP?
问题描述
从MySQL返回数据时,无论MySQL数据类型如何,数据都会自动以字符串形式返回.
When data is returned from MySQL, it is automatically returned as strings, regardless of the MySQL data type.
有没有办法告诉MySQL/PHP维护数据类型(例如int),因此,如果查询int列,则会在PHP中得到一个整数而不是字符串?
Is there any way to tell MySQL/PHP to maintain the data types (e.g. int), so if you query an int column, you get an integer in PHP instead of a string?
推荐答案
好的,您可以 类型转换 使用PHP转换返回的数据类型.
Well you can do Type casting to convert the type of returned data using PHP.
您可以查看 另一种方式是: 这篇关于如何从MySQL中获取一个整数作为PHP中的整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!int
,
$foo = (array)$foo;
$foo = (b)$foo; // from PHP 5.2.1
$foo = (binary)$foo; // from PHP 5.2.1
$foo = (bool)$foo;
$foo = (boolean)$foo;
$foo = (double)$foo;
$foo = (float)$foo;
$foo = (int)$foo;
$foo = (integer)$foo;
$foo = (object)$foo;
$foo = (real)$foo;
$foo = (string)$foo;