PHP SQL query builder and executor, using PDO.
π Go to documentation
Installation via composer:
composer require tomrf/seminorm
$db = new \Tomrf\Seminorm\Seminorm(
new PdoConnection(
PdoConnection::dsn(
'mysql',
'my_database',
'localhost',
),
'username',
'password',
[] // array of PDO options, ATTR_PERSISTENT, ATTR_ERRMODE etc..
),
new Factory(QueryBuilder::class),
new Factory(PdoQueryExecutor::class),
null, // optional row class, defaults to array
null, // optional data value class, defaults to string
);
$rows = $db->execute(
'SELECT * FROM `my_table` WHERE id = :id',
[ 'id' => 1 ]
)->findMany();
$rowId = $db->execute(
$db->query()->insertInto(
'my_table',
[ 'name' => 'My Name', 'email' => '[email protected]' ]
)
)->getLastInsertId();
...
composer test
This project is released under the MIT License (MIT). See LICENSE for more information.
- Tomrf\Seminorm\Seminorm
- Tomrf\Seminorm\Data\ImmutableArrayObject
- Tomrf\Seminorm\Data\Row
- Tomrf\Seminorm\Data\Value
- Tomrf\Seminorm\Factory\Factory
- Tomrf\Seminorm\Pdo\PdoConnection
- Tomrf\Seminorm\Pdo\PdoQueryExecutor
- Tomrf\Seminorm\QueryBuilder\QueryBuilder
- Tomrf\Seminorm\Sql\SqlCompiler
public function __construct(
Tomrf\Seminorm\Pdo\PdoConnection $connection,
Tomrf\Seminorm\Factory\Factory $queryBuilderFactory,
Tomrf\Seminorm\Factory\Factory $queryExecutorFactory,
?string $rowClass = '',
?string $valueClass = ''
): void
Return the active connection.
public function getConnection(): Tomrf\Seminorm\Pdo\PdoConnection
public function query(): Tomrf\Seminorm\QueryBuilder\QueryBuilder
public function execute(
Tomrf\Seminorm\Interface\QueryBuilderInterface|string $query,
array $parameters = []
): Tomrf\Seminorm\Pdo\PdoQueryExecutor
@param array<int|string,mixed> $parameters
Sets a logger.
public function setLogger(
Psr\Log\LoggerInterface $logger
): void
@param \Tomrf\Seminorm\LoggerInterface $logger
public function __get(
string $name
): mixed
public function __isset(
mixed $name
): void
public function offsetSet(
mixed $key,
mixed $value
): void
@SuppressWarnings (PHPMD.UnusedFormalParameter)
public function offsetUnset(
mixed $key
): void
@SuppressWarnings (PHPMD.UnusedFormalParameter)
public function offsetGet(
mixed $key
): mixed
public function offsetExists(
mixed $key
): bool
public function __construct(
object|array $array = [],
int $flags = 0,
string $iteratorClass = 'ArrayIterator'
): void
public function append(
mixed $value
): void
public function getArrayCopy(): void
public function count(): void
public function getFlags(): void
public function setFlags(
int $flags
): void
public function asort(
int $flags = 0
): void
public function ksort(
int $flags = 0
): void
public function uasort(
callable $callback
): void
public function uksort(
callable $callback
): void
public function natsort(): void
public function natcasesort(): void
public function unserialize(
string $data
): void
public function serialize(): void
public function __serialize(): void
public function __unserialize(
array $data
): void
public function getIterator(): void
public function exchangeArray(
object|array $array
): void
public function setIteratorClass(
string $iteratorClass
): void
public function getIteratorClass(): void
public function __debugInfo(): void
public function toArray(): array
@return array <string,mixed>
public function toJson(): string
public function __get(
string $name
): mixed
public function __isset(
mixed $name
): void
public function offsetSet(
mixed $key,
mixed $value
): void
@SuppressWarnings (PHPMD.UnusedFormalParameter)
public function offsetUnset(
mixed $key
): void
@SuppressWarnings (PHPMD.UnusedFormalParameter)
public function offsetGet(
mixed $key
): mixed
public function offsetExists(
mixed $key
): bool
public function __construct(
object|array $array = [],
int $flags = 0,
string $iteratorClass = 'ArrayIterator'
): void
public function append(
mixed $value
): void
public function getArrayCopy(): void
public function count(): void
public function getFlags(): void
public function setFlags(
int $flags
): void
public function asort(
int $flags = 0
): void
public function ksort(
int $flags = 0
): void
public function uasort(
callable $callback
): void
public function uksort(
callable $callback
): void
public function natsort(): void
public function natcasesort(): void
public function unserialize(
string $data
): void
public function serialize(): void
public function __serialize(): void
public function __unserialize(
array $data
): void
public function getIterator(): void
public function exchangeArray(
object|array $array
): void
public function setIteratorClass(
string $iteratorClass
): void
public function getIteratorClass(): void
public function __debugInfo(): void
public function __construct(
string|int|float|bool|null $data
): void
public function __toString(): string
public function asString(): string
public function asInt(): int
public function asFloat(): float
public function asBool(): bool
public function isNumeric(): bool
public function isInt(): bool
public function isString(): bool
public function isBool(): bool
public function isNull(): bool
public function getType(): string
public function __construct(
string $class
): void
@param class-string $class
public function make(
mixed $params
): mixed
public function __construct(
PDO|string $dsnOrPdo,
?string $username = '',
?string $password = '',
?array $options = []
): void
@param \PDO|string $dsnOrPdo DSN string or an existing PDO object
@param null|array<int,int> $options PDO options array
Get the PDO resource object for this connection.
public function getPdo(): ?PDO
Get PDO options array for this connection.
public function getOptions(): ?array
@return null|array<int,int>
Returns true if database connection has been established.
public function isConnected(): bool
Get the value of DSN.
public function getDsn(): ?string
Get the value of username.
public function getUsername(): ?string
Static helper function to build DSN string for PDO.
public static function dsn(
string $driver,
string $dbname,
?string $host = '',
int $port = 3306,
string $charset = 'utf8mb4'
): string
Connect to the database if not already connected.
public function connect(): void
@throws \RuntimeException
Disconnect from the database.
public function disconnect(): void
Mask password when dumping.
public function __debugInfo(): array
@return array<string,string|null|array<int,int>>
public function __construct(
Tomrf\Seminorm\Pdo\PdoConnection $connection,
?string $rowClass = '',
?string $valueClass = ''
): void
Returns the number of rows affected by the last SQL statement.
public function getRowCount(): int
Returns the last inserted row ID as string.
public function getLastInsertId(): string|false
Prepare and execute PDOStatement from an instance of QueryBuilderInterface.
public function execute(
Tomrf\Seminorm\Interface\QueryBuilderInterface|string $query,
array $parameters = []
): static
@throws \PDOException
Fetch next row from the result set as Row.
public function findOne(): object|array|null
@return null|(null|object|string)[]|object
Fetch all rows from query result set.
public function findMany(): object|array
@return array<int,(null|object|string)[]|object>
public function __toString(): string
public function selectFrom(
string $table,
string $columns
): static
Insert a row into a table
public function insertInto(
string $table,
array $values = []
): static
@param string $table
@param array<string,int|string|float|null> $values
@throws \InvalidArgumentException
public function update(
string $table,
array $values = []
): static
@param array<string,int|string|float|null> $values
@throws \InvalidArgumentException
public function deleteFrom(
string $table
): static
public function set(
string $column,
string|int|float $value
): static
public function setRaw(
string $column,
string $expression
): static
public function setFromArray(
array $values
): static
@param array<string,null|float|int|string> $values
@throws \InvalidArgumentException
public function alias(
string $expression,
string $alias
): static
public function join(
string $table,
string $joinCondition,
?string $joinType = ''
): static
public function limit(
int $limit,
?int $offset = null
): static
public function offset(
int $offset
): static
public function onDuplicateKey(
string $expression
): static
public function getQuery(): string
public function getQueryParameters(): array
@return (null|bool|float|int|string)[]
public function orderByAsc(
string $column
): static
public function orderByDesc(
string $column
): static
public function select(
string $columns
): static
public function selectAs(
string $expression,
string $alias
): static
public function selectRaw(
string $expressions
): static
public function selectRawAs(
string $expression,
string $alias
): static
public function where(
string $column,
string $operator,
string|int|float $value
): static
public function whereRaw(
string $expression
): static
public function whereColumnRaw(
string $column,
string $expression
): static
public function whereEqual(
string $column,
string|int|float $value
): static
public function whereNotEqual(
string $column,
string|int|float $value
): static
public function whereNull(
string $column
): static
public function whereNotNull(
string $column
): static
public function getQuery(): string
public function getQueryParameters(): array
@return (null|bool|float|int|string)[]
Generated 2022-11-11T01:32:36+01:00 using πtomrf/readme-gen