Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
$stmt = $mysqli->prepare('SELECT 1 as `asd`,23 as `a`,4 as `bcvbvc`');
$stmt->execute();
$stmt->store_result();
$meta = $stmt->result_metadata();
$fields = $meta->fetch_fields();
$columnNames = array_map(static function (stdClass $field): string {
return $field->name;
}, $fields);
$boundValues = array_fill(0, count($columnNames), null);
$refs = [];
foreach ($boundValues as &$value) {
$refs[] =& $value;
}
$stmt->bind_result(...$refs);
$stmt->fetch();
$values = [];
foreach ($boundValues as $v) {
$values[] = $v;
}
var_dump([...$boundValues]);