Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Zend Db Laravel Package

zendframework/zend-db

Zend\Db is a database abstraction layer for PHP, offering SQL builders, adapters, platform-specific quoting, and result set utilities. It supports multiple drivers and helps you write portable, secure queries while keeping low-level control when you need it.

View on GitHub
Deep Wiki
Context7

Row Gateways

Zend\Db\RowGateway is a sub-component of zend-db that implements the Row Data Gateway pattern described in the book Patterns of Enterprise Application Architecture. Row Data Gateways model individual rows of a database table, and provide methods such as save() and delete() that persist the row to the database. Likewise, after a row from the database is retrieved, it can then be manipulated and save()'d back to the database in the same position (row), or it can be delete()'d from the table.

RowGatewayInterface defines the methods save() and delete():

namespace Zend\Db\RowGateway;

interface RowGatewayInterface
{
    public function save();
    public function delete();
}

Quick start

RowGateway is generally used in conjunction with objects that produce Zend\Db\ResultSets, though it may also be used standalone. To use it standalone, you need an Adapter instance and a set of data to work with.

The following demonstrates a basic use case.

use Zend\Db\RowGateway\RowGateway;

// Query the database:
$resultSet = $adapter->query('SELECT * FROM `user` WHERE `id` = ?', [2]);

// Get array of data:
$rowData = $resultSet->current()->getArrayCopy();

// Create a row gateway:
$rowGateway = new RowGateway('id', 'my_table', $adapter);
$rowGateway->populate($rowData, true);

// Manipulate the row and persist it:
$rowGateway->first_name = 'New Name';
$rowGateway->save();

// Or delete this row:
$rowGateway->delete();

The workflow described above is greatly simplified when RowGateway is used in conjunction with the TableGateway RowGatewayFeature. In that paradigm, select() operations will produce a ResultSet that iterates RowGateway instances.

As an example:

use Zend\Db\TableGateway\Feature\RowGatewayFeature;
use Zend\Db\TableGateway\TableGateway;

$table = new TableGateway('artist', $adapter, new RowGatewayFeature('id'));
$results = $table->select(['id' => 2]);

$artistRow = $results->current();
$artistRow->name = 'New Name';
$artistRow->save();

ActiveRecord Style Objects

If you wish to have custom behaviour in your RowGateway objects — essentially making them behave similarly to the ActiveRecord pattern), pass a prototype object implementing the RowGatewayInterface to the RowGatewayFeature constructor instead of a primary key:

use Zend\Db\TableGateway\Feature\RowGatewayFeature;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\RowGateway\RowGatewayInterface;

class Artist implements RowGatewayInterface
{
    protected $adapter;

    public function __construct($adapter)
    {
       $this->adapter = $adapter;
    }

    // ... save() and delete() implementations
}

$table = new TableGateway('artist', $adapter, new RowGatewayFeature(new Artist($adapter)));
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4