-
Notifications
You must be signed in to change notification settings - Fork 0
formatData
Corey Avis edited this page Sep 23, 2026
·
2 revisions
This method is an internal structural utility. It acts as a data-mapping transformer engine that automatically intercepts raw database record arrays returned by MySQLi and reshapes them to match your fluid chain configuration settings (filter and output).
formatData(mixed $data): mixed
data (mixed)
: The raw associative array output fetched via MYSQLI_ASSOC.
(mixed)
: Returns your query results as a cleanly unwrapped value, array, object, or string format, dynamically matching your specified ->output() configuration.
When passed an empty dataset (zero records found), this method bypasses structural unwrapping and flattens into the following fixed type formats:
| Configured Output Type | Returned Empty Representation | Description / Use Case |
|---|---|---|
| array | [] |
Safe for un-nested foreach loops. |
| json | "[]" |
Keeps frontend/API clients from crashing on parsing. |
| object | stdClass Object () |
Protects OOP accessors from calling methods on non-objects. |
| serial | "a:0:{}" |
Can be safely serialzed/unserialized natively. |
| integer | 0 |
Math-safe fallback for empty numeric operations or counts. |
| string |
'' (empty string) |
Represents the semantic absence of text. |
| auto | null |
Perfect for quick null-coalescing operations (??). |
$db->formatData($data);
| Config Key | Default Value | Allowed Values | Description |
|---|---|---|---|
| output | auto | string (See: Output) | Default output data type. |
- No debug errors.