setOutputMode()
Defines the return format of query results globally for this instance. Affects get()
, getOne()
, rawQuery()
, and other read operations.
Signature:
public function setOutputMode(string $mode): self
// Allowed values: 'array' | 'object' | 'json'
Supported Modes
array
(default) – returns results as associative arraysobject
– returns results as stdClass objectsjson
– returns results as a JSON string (UTF-8-safe)
Example: switch to object mode
// Return results as object
$db->setOutputMode('object');
$users = $db->get('test_users');
Example: return JSON response
// Return as JSON
$db->setOutputMode('json');
echo $db->get('test_orders');
Note: JSON mode disables return-key mapping and object hydration. Use
array
or object
mode for structured manipulation.
Deprecated: The methods
$db->arrayBuilder()
, objectBuilder()
, and jsonBuilder()
are deprecated and have been removed as of v1.5.x
.
Use Instead: The new method
Old methods relied on static flags, which made them unsafe in environments with multiple database instances.
setOutputMode('array' | 'object' | 'json')
is instance-safe and replaces the legacy builder methods.Old methods relied on static flags, which made them unsafe in environments with multiple database instances.
Why were these methods removed?
The legacy builder methods used static flags internally, which caused side effects when using multiple PDOdb instances.
The new
The legacy builder methods used static flags internally, which caused side effects when using multiple PDOdb instances.
The new
setOutputMode('array' | 'object' | 'json')
method is instance-safe and allows consistent results across multiple connections.