如何从MySQL中获取一个整数作为PHP中的整数? [英] How to get an integer from MySQL as integer in PHP?

查看:48
本文介绍了如何从MySQL中获取一个整数作为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.

您可以查看 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;

这篇关于如何从MySQL中获取一个整数作为PHP中的整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆