Skip to content

Re-use prepared PDO Statements #12

@holtkamp

Description

@holtkamp

Might be a micro-optimization, but it might be an idea to re-use PDO Statements.

Something like:

class PDOAdapter extends AbstractAdapter
{
    private $writeStatement;

    private function getWriteStatement() : PDOStatement {
        return $this->writeStatement ?: $this->writeStatement = $this->pdo->prepare(
            "INSERT INTO {$this->table} (path, contents, size, type, mimetype, timestamp) VALUES(:path, :contents, :size, :type, :mimetype, :timestamp)"
        );
    }

    private function write() {
       $statement = $this->getWriteStatement();

       //do magic
    }
}

In case a lot of writes / reads, etc are involved, this prevents assembling a new PDO Statement over and over 🤓

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions