php - Detect data type while using fetch_array with MySQLi -
while fetching array mysqli in way such that
$sql = <<<sql select * `users` `live` = 1 sql; if(!$result = $db->query($sql)){ die('there error running query [' . $db->error . ']'); } while($row = $result->fetch_assoc()){ echo var_dump($row); }
i obtain associative arrays values of type string
.
which elegant way detect column type (varchar, datetime, int, float) , fill associative arrays (or create unique associative array) right typing (string, integer, null)?
this useful while returning results json_encode
d further client-side processing.
thanks lot
first of all, asking wrong question.
don't need column type. matter of fact, can tell string number simple php condition already. neither method tell null.
try this
$sql = "select * users live = 1"; $stm = $db->prepare($sql) or trigger_error($db->error); $stm->execute() or trigger_error($db->error); $res = $stm->get_result(); $row = mysqli_fetch_assoc($res);
if lucky, you'd types set.
if not - need enable mysqlnd in php
Comments
Post a Comment