php - How can I fetch correct datatypes from MySQL with PDO? -



php - How can I fetch correct datatypes from MySQL with PDO? -

my pdo fetch returns string.

i have user class id (int) , username (varchar).

when seek next sql request

$db->prepare('select * users id=:id_user'); $db->bindparam(':id_user', $id_user); $db->execute(); $user_data = $db->fetch(pdo::fetch_assoc);

and var_dump($user_data), id parameter string. how can create pdo respects right datatypes mysql ?

you utilize different *fetch_style*. if have user class, forcefulness pdo homecoming instance of user class with

$statement->fetchall(pdo::fetch_class, "user");

you can take care of properties validations , casting within user class, belongs.

related:

php pdo: fetching info objects - properties assigned before __construct called. correct? pdo php fetch class

php mysql pdo

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -