Skip to main content
The LibSQLTransaction class represents a database transaction in the LibSQL PHP extension. It allows for executing SQL statements within a transaction context, handling commits, rollbacks, and managing transactional behavior.

Constructor

The libSQL Transaction will construct when you using $db->transaction().

Methods

changes

Retrieves the number of rows changed by the last SQL statement.

Returns

  • (int) : The number of rows changed.

Example


isAutocommit

Checks if the transaction is set to autocommit.

Returns

  • (bool) : if autocommit is enabled return true, otherwise false.

Example


execute

Executes an SQL statement within the transaction.

Parameters

  • string $stmt: The SQL statement to execute.
  • array $parameters: The parameters for the statement (optional).

Returns

  • (int) : The number of affected rows.

Example


query

Executes a query within the transaction and returns the result set.

Parameters

  • string $stmt: The SQL statement to execute.
  • array $parameters: The parameters for the statement (optional).

Returns

  • (LibSQLResult): The result set of the query.

Example


commit

Commits the transaction.

Returns

  • (void)

Example


rollback

Rolls back the transaction.

Returns

  • (void)

Example


Usage Example