我试图用PDO
从MySQL数据库中获取数据,但不幸的是,PDO
返回的结果是一个字符串数组。我想在结果数组中保留原生MySQL数据类型。
我尝试将PDO::ATTR_DEFAULT_FETCH_MODE
设置为PDO::FETCH_ASSOC
和PDO::FETCH_OBJ
,但它仍然以字符串形式返回INT
数据。
下面是dump的结果:
array (size=1)
0 =>
object(stdClass)[27]
public 'id' => string '3' (length=1)
public 'avatar' => string '' (length=0)
public 'fullName' => string 'Mikheil Janiashvili' (length=19)
public 'email' => string '[email protected]' (length=17)
public 'phone' => string '23 3537 20 03544' (length=12)
public 'educationGE' => string '' (length=0)
public 'educationEN' => string '' (length=0)
public 'educationRU' => string '' (length=0)
public 'experienceGE' => string '' (length=0)
public 'experienceEN' => string '' (length=0)
public 'experienceRU' => string '' (length=0)
public 'descriptionGE' => string '' (length=0)
public 'descriptionEN' => string '' (length=0)
public 'descriptionRU' => string '' (length=0)
1条答案
按热度按时间vxbzzdmp1#
当你示例化你的PDO对象时,你需要告诉它使用MySQL的原生准备查询:
假设您使用的是PHP >= 5.3,您将使用mysqlnd库,它可以从准备好的查询中返回正确的数据类型。
范例: