我想有效地绑定列,然后将所有内容放入一个数组中。
<?php
$columns = array(
'DEVICE_CONFIG' => '',
'CONSUMABLE_INFO' => '',
'DEVICE_UNIQUE_ID' => '',
'STATUS' => '',
'STATUS_MESSAGE' => '',
'LAST_MESSAGE_TIME' => '',
'DEVICE_DESCRIPTION' => ''
);
$statement = $this->connection->prepare($sql);
$statement->execute();
$x = 1;
foreach($columns as $column => $index){
$$column = $index;
eval('$statement->bindColumn(' . $x++ . ', $' . $column . ');');
}
$output= array();
while($statement->fetch(\PDO::FETCH_BOUND)){
$temp = array();
foreach($columns as $columnName => $val){
eval("\$data = \$$columnName;");
$temp[$columnName] = $data;
}
$output[] = $temp;
}
?>