Reports whether an executed SQLite3 statement still has an unfinished result set.
The objective is to understand the behavior and operational limits, not only the method name.
What It Does
Reports whether an executed SQLite3 statement still has an unfinished result set.
Syntax and Return Value
SQLite3Stmt::busy(...)
The return value and exceptional cases depend on the call described here: Added in PHP 8.5; execute the statement before checking, and note that reset clears it.
Version requirement: PHP 8.5 or later. The method does not exist in PHP 8.4.
Example 1: Basic Use
Requires PHP 8.5+ and SQLite3; busy() reflects unfinished statement execution, not file lock contention.
<?php
if (PHP_VERSION_ID < 80500) throw new RuntimeException("PHP 8.5+ required");
$db = new SQLite3(":memory:");
$stmt = $db->prepare("SELECT 1 UNION ALL SELECT 2");
$res = $stmt->execute();
echo $stmt->busy() ? "not finished" : "not busy";
$res->fetchArray(SQLITE3_NUM);
Example 2: A Second Scenario
Requires PHP 8.5+ and SQLite3; busy() reflects unfinished statement execution, not file lock contention. This additional check distinguishes the method's result from connection or statement state.
<?php
if (PHP_VERSION_ID < 80500) throw new RuntimeException("PHP 8.5+ required");
$db = new SQLite3(":memory:");
$stmt = $db->prepare("SELECT 1 UNION ALL SELECT 2");
$res = $stmt->execute();
echo $stmt->busy() ? "not finished" : "not busy";
$res->fetchArray(SQLITE3_NUM);
$stmt->reset();
echo $stmt->busy() ? "still busy" : "reset state";
Example 3: Practical Checks
Requires PHP 8.5+ and SQLite3; busy() reflects unfinished statement execution, not file lock contention. This additional check distinguishes the method's result from connection or statement state.
<?php
if (PHP_VERSION_ID < 80500) throw new RuntimeException("PHP 8.5+ required");
$db = new SQLite3(":memory:");
$stmt = $db->prepare("SELECT 1 UNION ALL SELECT 2");
$res = $stmt->execute();
echo $stmt->busy() ? "not finished" : "not busy";
$res->fetchArray(SQLITE3_NUM);
$res->fetchArray(SQLITE3_NUM);
echo "Busy after fetching one row: " . ($stmt->busy() ? "yes" : "no");
Important Behavior and Edge Cases
Added in PHP 8.5; execute the statement before checking, and note that reset clears it.
For production use, also account for error handling, data validation, resource limits and environment-specific driver behavior.
Comparison with Related Approaches
| Approach | Important distinction |
|---|---|
| SQLite3Stmt::busy | Reports whether an executed SQLite3 statement still has an unfinished result set. |
| Related API / pattern | SQLite3Stmt::reset returns a statement to its initial state rather than testing it. |
Common Beginner Mistakes
| Mistake | Correct approach |
|---|---|
| Assuming the happy path covers edge cases | Added in PHP 8.5; execute the statement before checking, and note that reset clears it. |
| Using a related API interchangeably | SQLite3Stmt::reset returns a statement to its initial state rather than testing it. |
Key Takeaways
- Reports whether an executed SQLite3 statement still has an unfinished result set.
- Added in PHP 8.5; execute the statement before checking, and note that reset clears it.
- SQLite3Stmt::reset returns a statement to its initial state rather than testing it.
Choose this API or pattern when its exact semantics match your task, and verify the result against the database driver and runtime used by your application.