bhenk/msdata
About
Basic implementation of Data Object and Data Access Object for MySql database.
Source code: https://github.com/bhenk/msdata-d
Usage
Installation
composer require bhenk/msdata
Configuration
See MysqlConnector
Persist your data
Extend the Data Object Entity
Extend the Data Access Object AbstractDao
Run AbstractDao::createTable once.
Creation of tables
Data types string, int, bool and float, when used in Entities will be converted to proper database types automatically. Caveat: String is converted to VARCHAR(255). If your strings are larger you’ll have to override the method AbstractDao::getCreateTableStatement and provide your own.
Simple Data Objects
msData is on purpose kept simple. There will be one table for each Data Object. Data Objects have only primitive types: string, int, bool and float. Extend Entity, create a constructor for all your Data Object fields, generate getters and setters and you’re basically done. The corresponding Data Access Object needs only implementing of two methods: AbstractDao::getDataObjectName and AbstractDao::getTableName.
Complexity in your business layer
Mixes of different entities is foreseen to take place in your business layer. For instance PersonWithAddress(es) is a mix of the Data Objects PersonDo and (one or more) AddressDo. Objects like Date, Time, DateTime etc. are represented in your Data Objects as strings, or other primitive types, though they may be represented in the database with appropriate types and queried as such, and in your business layer again as DateTimeImmutable(s) etc.
Relations
The Data Access Object AbstractJoinDao and Data Object Join can be used to express many-to-many relationships, based on a join-table with foreign keys. Below is a complete diagram covering database, data-layer and business-layer.
Business Objects (Bo’s) are created by their corresponding Store Object. Store Objects rely on their Data Access Object (Dao) to materialize the type of Bo. Bo’s have a dependency on their Relations Object which in turn has a dependency on the opposite Store Object, in order to materialize the opposite ends of the relation. Relations Objects may have lazy methods to fetch their (Join) Data Objects and related Bo’s, in order to keep database traffic at a minimum.
After a Store Object has persisted a Bo, it calls on the Relations Object to persist the relations.
A Relations Object may keep track of more than one type of relation, so Bo’s can have multiple relations to multiple other Bo-types. For each type of relation the Relations Object than has distinguished Dao’s and Do’s, backed by separate join tables.
Although there are no objections to complete symmetry, adding and removing of relations is often done from one side only, while the other side has readonly methods on their Relations Object. So for instance a Person can add and remove Addresses, while from the Address Object you can only obtain which Persons are living or working there.
api-docs
msdata
abc
Depends on |
Dependency invoked by |
---|---|
Interfaces and abstract implementations of Data Objects and Data Access Objects
AbstractDao
namespace |
bhenk\msdata\abc |
predicates |
Abstract |
known subclasses |
Data Access Object with basic functionality
In most cases subclasses only need to implement getDataObjectName and getTableName. If getCreateTableStatement is not sufficient override that method as well.
This class expects Entities that subclass other Entity implementations to have parent-first in their __construct() and toArray() functions, i.e.:
class A extends Entity
class B extends A
In their __construct() and toArray() functions, properties/parameters have the order:
ID, {props of A}, {props of B}
Methods
AbstractDao::dropTable
predicates |
public |
Drop table if it exists
Tries to drop the table with the name returned by AbstractDao::getTableName.
public function dropTable(): bool
AbstractDao::createTable
predicates |
public |
Create a table in the database
The statement used is the one from getCreateTableStatement.
public function createTable(
Parameter #0 [ <optional> bool $drop = false ]
): int
AbstractDao::getTableName
predicates |
public | abstract |
Get the name of the table that will store the Entities this class provides access to
public abstract function getTableName(): string
AbstractDao::getCreateTableStatement
predicates |
public |
Produces a minimal CreateTableStatement
CREATE TABLE IF NOT EXISTS `%table_name%`
(
`ID` INT NOT NULL AUTO_INCREMENT,
`%int_prop%` INT,
`%string_prop%` VARCHAR(255),
`%bool_prop%` BOOLEAN,
`%float_prop%` FLOAT,
PRIMARY KEY (`ID`)
);
In the above %xyz% is placeholder for table name or property name. Notice that string type parameters have a limited length of 255 characters.
Subclasses may override. The table MUST have the same name as the one returned by the method getTableName.
public function getCreateTableStatement(): string
AbstractDao::getDataObjectName
predicates |
public | abstract |
Get the fully qualified classname of the Entity this class provides access to
public abstract function getDataObjectName(): string
AbstractDao::insert
predicates |
public |
Insert the given Entity
With $insertID set to false (this is the default), the ID of the Entity (if any) will be ignored. Returns an Entity equal to the given Entity with the new ID.
In order to be able to reconstruct a table, the ID of the Entity can be inserted as well. Set $insertID to true to achieve this.
public function insert(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
Parameter #1 [ <optional> bool $insertID = false ]
): Entity
AbstractDao::insertBatch
predicates |
public |
Insert the Entities from the given array
The ID of the Entities (if any) will be ignored. Returns an array of Entities equal to the given Entities with new IDs and ID as array key. This default behaviour can be altered by providing a closure that receives each inserted entity and decides what key will be returned:
$func = function(Entity $entity): int {
return $entity->getID();
};
In order to be able to reconstruct a table, the ID of the Entities can be inserted as well. Set $insertID to true to achieve this.
public function insertBatch(
Parameter #0 [ <required> array $entity_array ]
Parameter #1 [ <optional> ?Closure $func = NULL ]
Parameter #2 [ <optional> bool $insertID = false ]
): array
AbstractDao::update
predicates |
public |
Update the given Entity
public function update(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
): int
AbstractDao::updateBatch
predicates |
public |
Update the Entities in the given array
public function updateBatch(
Parameter #0 [ <required> array $entity_array ]
): int
AbstractDao::delete
predicates |
public |
Delete the row with the given ID
public function delete(
Parameter #0 [ <required> int $ID ]
): int
AbstractDao::deleteBatch
predicates |
public |
Delete rows with the given IDs
public function deleteBatch(
Parameter #0 [ <required> array $ids ]
): int
AbstractDao::select
predicates |
public |
Fetch the Entity with the given ID
public function select(
Parameter #0 [ <required> int $ID ]
): ?Entity
AbstractDao::selectBatch
predicates |
public |
Select Entities with the given IDs
The returned Entity[] array has Entity IDs as keys.
public function selectBatch(
Parameter #0 [ <required> array $ids ]
): array
AbstractDao::deleteWhere
predicates |
public |
Delete Entity rows with a where-clause
DELETE FROM %table_name% WHERE %expression%
public function deleteWhere(
Parameter #0 [ <required> string $where_clause ]
): int
AbstractDao::selectWhere
predicates |
public |
Select Entities with a where-clause
SELECT FROM %table_name% WHERE %expression% LIMIT %offset%, %limit%;
The optional $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.
$func = function(Entity $entity): int {
return $entity->getID();
};
public function selectWhere(
Parameter #0 [ <required> string $where_clause ]
Parameter #1 [ <optional> int $offset = 0 ]
Parameter #2 [ <optional> int $limit = bhenk\msdata\abc\PHP_INT_MAX ]
Parameter #3 [ <optional> ?Closure $func = NULL ]
): array
AbstractDao::selectSql
predicates |
public |
Select Entities with a sql statement
The optional $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.
$func = function(Entity $entity): int {
return $entity->getID();
};
If the $sql selects not all fields from the designated table or selects from tables other than the designated, the result is unpredictable.
public function selectSql(
Parameter #0 [ <required> string $sql ]
Parameter #1 [ <optional> ?Closure $func = NULL ]
): array
AbstractDao::execute
predicates |
public |
Execute the given query
public function execute(
Parameter #0 [ <required> string $sql ]
): array|bool
Sat, 01 Jul 2023 13:02:22 +0000
AbstractJoinDao
namespace |
bhenk\msdata\abc |
predicates |
Abstract |
extends |
|
hierarchy |
|
known subclasses |
Abstract Dao for a join table
The corresponding Data Object is envisaged to extend Join.
The relationship is symmetric.
A Join with the field $deleted set to true will be deleted on any call to AbstractJoinDao::updateLeftJoin or AbstractJoinDao::updateRightJoin.
Methods
AbstractJoinDao::selectLeft
predicates |
public |
Select on left hand foreign key
public function selectLeft(
Parameter #0 [ <required> int $fk_left ]
): array
AbstractJoinDao::selectRight
predicates |
public |
Select on right hand foreign key
public function selectRight(
Parameter #0 [ <required> int $fk_right ]
): array
AbstractJoinDao::updateLeftJoin
predicates |
public |
Update Joins with a common FK_LEFT
This method deletes deleted Joins; updates existing Joins and inserts new Joins.
Side effect: the common $fk_left will be set on all Joins.
public function updateLeftJoin(
Parameter #0 [ <required> int $fk_left ]
Parameter #1 [ <required> array $joins ]
): array
AbstractJoinDao::updateRightJoin
predicates |
public |
Update Joins with a common FK_RIGHT
This method deletes deleted Joins; updates existing Joins and inserts new Joins.
Side effect: the common $fk_right will be set on all Joins.
public function updateRightJoin(
Parameter #0 [ <required> int $fk_right ]
Parameter #1 [ <required> array $joins ]
): array
AbstractJoinDao::dropTable
predicates |
public |
inherited from |
Drop table if it exists
Tries to drop the table with the name returned by AbstractDao::getTableName.
public function dropTable(): bool
AbstractJoinDao::createTable
predicates |
public |
inherited from |
Create a table in the database
The statement used is the one from getCreateTableStatement.
public function createTable(
Parameter #0 [ <optional> bool $drop = false ]
): int
AbstractJoinDao::getTableName
predicates |
public | abstract |
inherited from |
Get the name of the table that will store the Entities this class provides access to
public abstract function getTableName(): string
AbstractJoinDao::getCreateTableStatement
predicates |
public |
inherited from |
Produces a minimal CreateTableStatement
CREATE TABLE IF NOT EXISTS `%table_name%`
(
`ID` INT NOT NULL AUTO_INCREMENT,
`%int_prop%` INT,
`%string_prop%` VARCHAR(255),
`%bool_prop%` BOOLEAN,
`%float_prop%` FLOAT,
PRIMARY KEY (`ID`)
);
In the above %xyz% is placeholder for table name or property name. Notice that string type parameters have a limited length of 255 characters.
Subclasses may override. The table MUST have the same name as the one returned by the method getTableName.
public function getCreateTableStatement(): string
AbstractJoinDao::getDataObjectName
predicates |
public | abstract |
inherited from |
Get the fully qualified classname of the Entity this class provides access to
public abstract function getDataObjectName(): string
AbstractJoinDao::insert
predicates |
public |
inherited from |
Insert the given Entity
With $insertID set to false (this is the default), the ID of the Entity (if any) will be ignored. Returns an Entity equal to the given Entity with the new ID.
In order to be able to reconstruct a table, the ID of the Entity can be inserted as well. Set $insertID to true to achieve this.
public function insert(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
Parameter #1 [ <optional> bool $insertID = false ]
): Entity
AbstractJoinDao::insertBatch
predicates |
public |
inherited from |
Insert the Entities from the given array
The ID of the Entities (if any) will be ignored. Returns an array of Entities equal to the given Entities with new IDs and ID as array key. This default behaviour can be altered by providing a closure that receives each inserted entity and decides what key will be returned:
$func = function(Entity $entity): int {
return $entity->getID();
};
In order to be able to reconstruct a table, the ID of the Entities can be inserted as well. Set $insertID to true to achieve this.
public function insertBatch(
Parameter #0 [ <required> array $entity_array ]
Parameter #1 [ <optional> ?Closure $func = NULL ]
Parameter #2 [ <optional> bool $insertID = false ]
): array
AbstractJoinDao::update
predicates |
public |
inherited from |
Update the given Entity
public function update(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
): int
AbstractJoinDao::updateBatch
predicates |
public |
inherited from |
Update the Entities in the given array
public function updateBatch(
Parameter #0 [ <required> array $entity_array ]
): int
AbstractJoinDao::delete
predicates |
public |
inherited from |
Delete the row with the given ID
public function delete(
Parameter #0 [ <required> int $ID ]
): int
AbstractJoinDao::deleteBatch
predicates |
public |
inherited from |
Delete rows with the given IDs
public function deleteBatch(
Parameter #0 [ <required> array $ids ]
): int
AbstractJoinDao::select
predicates |
public |
inherited from |
Fetch the Entity with the given ID
public function select(
Parameter #0 [ <required> int $ID ]
): ?Entity
AbstractJoinDao::selectBatch
predicates |
public |
inherited from |
Select Entities with the given IDs
The returned Entity[] array has Entity IDs as keys.
public function selectBatch(
Parameter #0 [ <required> array $ids ]
): array
AbstractJoinDao::deleteWhere
predicates |
public |
inherited from |
Delete Entity rows with a where-clause
DELETE FROM %table_name% WHERE %expression%
public function deleteWhere(
Parameter #0 [ <required> string $where_clause ]
): int
AbstractJoinDao::selectWhere
predicates |
public |
inherited from |
Select Entities with a where-clause
SELECT FROM %table_name% WHERE %expression% LIMIT %offset%, %limit%;
The optional $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.
$func = function(Entity $entity): int {
return $entity->getID();
};
public function selectWhere(
Parameter #0 [ <required> string $where_clause ]
Parameter #1 [ <optional> int $offset = 0 ]
Parameter #2 [ <optional> int $limit = bhenk\msdata\abc\PHP_INT_MAX ]
Parameter #3 [ <optional> ?Closure $func = NULL ]
): array
AbstractJoinDao::selectSql
predicates |
public |
inherited from |
Select Entities with a sql statement
The optional $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.
$func = function(Entity $entity): int {
return $entity->getID();
};
If the $sql selects not all fields from the designated table or selects from tables other than the designated, the result is unpredictable.
public function selectSql(
Parameter #0 [ <required> string $sql ]
Parameter #1 [ <optional> ?Closure $func = NULL ]
): array
AbstractJoinDao::execute
predicates |
public |
inherited from |
Execute the given query
public function execute(
Parameter #0 [ <required> string $sql ]
): array|bool
Sat, 01 Jul 2023 13:02:23 +0000
DataTypes
namespace |
bhenk\msdata\abc |
predicates |
Final | Enum |
implements |
Convertor for PHP-types to database-types
Constants
DataTypes::string
predicates |
public | enum case |
PHP string converts to database type VARCHAR(255)
enum(bhenk\msdata\abc\DataTypes::string)
DataTypes::int
predicates |
public | enum case |
PHP int converts to database type INT
enum(bhenk\msdata\abc\DataTypes::int)
DataTypes::bool
predicates |
public | enum case |
PHP bool converts to database type BOOLEAN
enum(bhenk\msdata\abc\DataTypes::bool)
DataTypes::float
predicates |
public | enum case |
PHP float converts to database type FLOAT
enum(bhenk\msdata\abc\DataTypes::float)
Methods
DataTypes::fromName
predicates |
public | static |
Get the database-type for the given PHP-type
public static function fromName(
Parameter #0 [ <required> string $name ]
): string
DataTypes::cases
predicates |
public | static |
implements |
public static function cases(): array
DataTypes::from
predicates |
public | static |
implements |
public static function from(
Parameter #0 [ <required> string|int $value ]
): static
DataTypes::tryFrom
predicates |
public | static |
implements |
public static function tryFrom(
Parameter #0 [ <required> string|int $value ]
): ?static
Sat, 01 Jul 2023 13:02:23 +0000
Entity
namespace |
bhenk\msdata\abc |
predicates |
Cloneable | Instantiable |
implements |
|
known subclasses |
Basic implementation of a data object
Constructor
Entity::__construct
predicates |
public | constructor |
Construct a new Entity
public function __construct(
Parameter #0 [ <optional> ?int $ID = NULL ]
)
Methods
Entity::clone
predicates |
public |
implements |
@inheritdoc
Create an Entity that equals this Entity
The newly created Entity gets the given ID or no ID if $ID is null.
@inheritdoc
from method EntityInterface::clone
public function clone(
Parameter #0 [ <optional> ?int $ID = NULL ]
): Entity
Entity::toArray
predicates |
public |
implements |
@inheritdoc
Express the properties of this Entity in an array
The returned array should be in such order that it can be fet to the static method EntityInterface::fromArray.
@inheritdoc
from method EntityInterface::toArray
see also
public function toArray(): array
Entity::getParents
predicates |
public |
Get the (Reflection) parents of this Entity in reverse order
class A extends Entity
class B extends A
returned array = [Entity-Reflection, A-Reflection, B-Reflection]
public function getParents(): array
Entity::fromArray
predicates |
public | static |
implements |
Create a new Entity
The order of the given array should be parent-first, i.e.:
class A extends Entity
class B extends A
In __construct(), toArray() and fromArray() functions, properties/parameters have the order:
ID, {props of A}, {props of B}
@inheritdoc
Create a new Entity from an array of properties
The given array should have the same order as the one gotten from EntityInterface::toArray.
@inheritdoc
from method EntityInterface::fromArray
public static function fromArray(
Parameter #0 [ <required> array $arr ]
): static
Entity::isSame
predicates |
public |
implements |
@inheritdoc
Test is same function
The given Entity is similar to this Entity if all properties, including ID, are equal.
@inheritdoc
from method EntityInterface::isSame
public function isSame(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
): bool
Entity::equals
predicates |
public |
implements |
@inheritdoc
Test equals function
The given Entity equals this Entity if all properties, except ID, are equal.
@inheritdoc
from method EntityInterface::equals
public function equals(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
): bool
Entity::getID
predicates |
public |
implements |
@inheritdoc
Get the ID of this Entity or null if it has no ID
@inheritdoc
from method EntityInterface::getID
public function getID(): ?int
Entity::__toString
predicates |
public |
implements |
String representation of this Entity
public function __toString(): string
Sat, 01 Jul 2023 13:02:23 +0000
EntityInterface
namespace |
bhenk\msdata\abc |
predicates |
Abstract | Interface |
implements |
|
known implementations |
Definition of a basic data object
Methods
EntityInterface::fromArray
predicates |
public | static | abstract |
Create a new Entity from an array of properties
The given array should have the same order as the one gotten from EntityInterface::toArray.
public static abstract function fromArray(
Parameter #0 [ <required> array $arr ]
): Entity
EntityInterface::getID
predicates |
public | abstract |
Get the ID of this Entity or null if it has no ID
public abstract function getID(): ?int
EntityInterface::toArray
predicates |
public | abstract |
Express the properties of this Entity in an array
The returned array should be in such order that it can be fet to the static method EntityInterface::fromArray.
public abstract function toArray(): array
EntityInterface::clone
predicates |
public | abstract |
Create an Entity that equals this Entity
The newly created Entity gets the given ID or no ID if $ID is null.
public abstract function clone(
Parameter #0 [ <optional> ?int $ID = NULL ]
): Entity
EntityInterface::equals
predicates |
public | abstract |
Test equals function
The given Entity equals this Entity if all properties, except ID, are equal.
public abstract function equals(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
): bool
EntityInterface::isSame
predicates |
public | abstract |
Test is same function
The given Entity is similar to this Entity if all properties, including ID, are equal.
public abstract function isSame(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
): bool
EntityInterface::__toString
predicates |
public | abstract |
public abstract function __toString(): string
Sat, 01 Jul 2023 13:02:23 +0000
Join
namespace |
bhenk\msdata\abc |
predicates |
Cloneable | Instantiable |
implements |
|
extends |
|
hierarchy |
A basic Entity for a join function
Join can be used when expressing a many-to-many relation
Constructor
Join::__construct
predicates |
public | constructor |
Constructs a new Join
public function __construct(
Parameter #0 [ <optional> ?int $ID = NULL ]
Parameter #1 [ <optional> ?int $FK_LEFT = NULL ]
Parameter #2 [ <optional> ?int $FK_RIGHT = NULL ]
Parameter #3 [ <optional> bool $deleted = false ]
)
Methods
Join::getFkLeft
predicates |
public |
Get the left hand foreign key
public function getFkLeft(): ?int
Join::setFkLeft
predicates |
public |
Set the left hand foreign key
public function setFkLeft(
Parameter #0 [ <required> ?int $FK_LEFT ]
): void
Join::getFkRight
predicates |
public |
Get the right hand foreign key
public function getFkRight(): ?int
Join::setFkRight
predicates |
public |
Set the right hand foreign key
public function setFkRight(
Parameter #0 [ <required> ?int $FK_RIGHT ]
): void
Join::isDeleted
predicates |
public |
Get whether this join-relation is deleted
public function isDeleted(): bool
Join::setDeleted
predicates |
public |
Sets whether this join-relation is deleted
public function setDeleted(
Parameter #0 [ <required> bool $deleted ]
): void
Join::clone
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Create an Entity that equals this Entity
The newly created Entity gets the given ID or no ID if $ID is null.
@inheritdoc
from method EntityInterface::clone
public function clone(
Parameter #0 [ <optional> ?int $ID = NULL ]
): Entity
Join::toArray
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Express the properties of this Entity in an array
The returned array should be in such order that it can be fet to the static method EntityInterface::fromArray.
@inheritdoc
from method EntityInterface::toArray
see also
public function toArray(): array
Join::getParents
predicates |
public |
inherited from |
Get the (Reflection) parents of this Entity in reverse order
class A extends Entity
class B extends A
returned array = [Entity-Reflection, A-Reflection, B-Reflection]
public function getParents(): array
Join::fromArray
predicates |
public | static |
implements |
|
inherited from |
Create a new Entity
The order of the given array should be parent-first, i.e.:
class A extends Entity
class B extends A
In __construct(), toArray() and fromArray() functions, properties/parameters have the order:
ID, {props of A}, {props of B}
@inheritdoc
Create a new Entity from an array of properties
The given array should have the same order as the one gotten from EntityInterface::toArray.
@inheritdoc
from method EntityInterface::fromArray
public static function fromArray(
Parameter #0 [ <required> array $arr ]
): static
Join::isSame
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Test is same function
The given Entity is similar to this Entity if all properties, including ID, are equal.
@inheritdoc
from method EntityInterface::isSame
public function isSame(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
): bool
Join::equals
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Test equals function
The given Entity equals this Entity if all properties, except ID, are equal.
@inheritdoc
from method EntityInterface::equals
public function equals(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
): bool
Join::getID
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Get the ID of this Entity or null if it has no ID
@inheritdoc
from method EntityInterface::getID
public function getID(): ?int
Join::__toString
predicates |
public |
implements |
|
inherited from |
String representation of this Entity
public function __toString(): string
Sat, 01 Jul 2023 13:02:23 +0000
Sat, 01 Jul 2023 13:02:22 +0000
connector
Database connectors
MysqlConnector
namespace |
bhenk\msdata\connector |
predicates |
Cloneable | Instantiable |
Static wrapper around a mysqli instance
Convenience class for a mysqli connection and configuration. Configuration options can be expressed in a configuration file. The configuration file can be set with the method MysqlConnector::setConfigFile or you can rely on auto-finding of the file.
If relying on auto-finding of configuration, this class will look for a configuration file with the name msd_config.php in a directory with the name config. The config directory should be a child of an ancestor directory of this code base:
{ancestor directory}/config/msd_config.php
The configuration file should return configuration options as an array:
<?php
return [
"hostname" => {string}, // required
"username" => {string}, // required
"password" => {string}, // required
"database" => {string}, // required
"port" => {int}, // optional, default 3306
"persistent" => {bool}, // optional, default true
"use_parameterized_queries" => {bool} // optional, default true
];
A connection via libmysqlclient will not allow binding parameters in execute and produce the following error:
ArgumentCountError: Binding parameters in execute is not supported with libmysqlclient
In that case set use_parameterized_queries to false.
A third method of setting the configuration is by programmatically calling MysqlConnector::setConfiguration with the appropriate array, like shown above.
Constants
MysqlConnector::CONFIG_DIR
predicates |
public |
Name of the directory where a configuration file is expected
string(6) "config"
MysqlConnector::CONFIG_FILE
predicates |
public |
Name of the expected configuration file
string(14) "msd_config.php"
Methods
MysqlConnector::get
predicates |
public | static |
Get the singleton instance of this class
public static function get(): MysqlConnector
MysqlConnector::closeConnection
predicates |
public | static |
Close the connection (if any)
public static function closeConnection(): void
MysqlConnector::getConfigFile
predicates |
public |
Get the (absolute path to the) configuration file
see also
public function getConfigFile(): string|bool
MysqlConnector::setConfigFile
predicates |
public |
Set the configuration file
When not using auto-find of configuration, this method must be called before a call to MysqlConnector::getConnector.
public function setConfigFile(
Parameter #0 [ <required> string|bool $config_file ]
): void
MysqlConnector::statusInfo
predicates |
public |
Returns status info
Something like
Uptime: 80984
Threads: 2
Questions: 1327
Slow queries: 0
Opens: 432
Flush tables: 3
Open tables: 274
Queries per second avg: 0.016"
public function statusInfo(): string|bool
MysqlConnector::getConnector
predicates |
public |
Get the connector
public function getConnector(): mysqli
MysqlConnector::useParameterizedQueries
predicates |
public |
The value of the configuration option use_parameterized_queries
public function useParameterizedQueries(): bool
MysqlConnector::getConfiguration
predicates |
public |
Get the configuration
If configuration not set, the array will be read from the configuration file, either from the configuration file as given with MysqlConnector::setConfigFile or from the auto-find configuration file at
{ancestor directory}/config/msd_config.php
public function getConfiguration(): array
MysqlConnector::setConfiguration
predicates |
public |
Set configuration as an array
see also
public function setConfiguration(
Parameter #0 [ <required> array $configuration ]
): void
MysqlConnector::connectionInfo
predicates |
public |
Returns client and server info
Something like
client: mysqlnd 8.2.1
server: 8.0.32
host: 127.0.0.1 via TCP/IP
protocol version: 10
character set: utf8mb4
public function connectionInfo(): string
Sat, 01 Jul 2023 13:02:23 +0000
Sat, 01 Jul 2023 13:02:23 +0000
node
Depends on |
Dependency invoked by |
---|---|
NodeDao
namespace |
bhenk\msdata\node |
predicates |
Cloneable | Instantiable |
extends |
|
hierarchy |
Constants
NodeDao::TABLE_NAME
predicates |
public |
string(8) "tbl_node"
Methods
NodeDao::getDataObjectName
predicates |
public |
implements |
public function getDataObjectName(): string
NodeDao::getTableName
predicates |
public |
implements |
public function getTableName(): string
NodeDao::selectChildren
predicates |
public |
public function selectChildren(
Parameter #0 [ <required> int $ID ]
): array
NodeDao::selectGenerationNumbers
predicates |
public |
public function selectGenerationNumbers(): array
NodeDao::dropTable
predicates |
public |
inherited from |
Drop table if it exists
Tries to drop the table with the name returned by AbstractDao::getTableName.
public function dropTable(): bool
NodeDao::createTable
predicates |
public |
inherited from |
Create a table in the database
The statement used is the one from getCreateTableStatement.
public function createTable(
Parameter #0 [ <optional> bool $drop = false ]
): int
NodeDao::getCreateTableStatement
predicates |
public |
inherited from |
Produces a minimal CreateTableStatement
CREATE TABLE IF NOT EXISTS `%table_name%`
(
`ID` INT NOT NULL AUTO_INCREMENT,
`%int_prop%` INT,
`%string_prop%` VARCHAR(255),
`%bool_prop%` BOOLEAN,
`%float_prop%` FLOAT,
PRIMARY KEY (`ID`)
);
In the above %xyz% is placeholder for table name or property name. Notice that string type parameters have a limited length of 255 characters.
Subclasses may override. The table MUST have the same name as the one returned by the method getTableName.
public function getCreateTableStatement(): string
NodeDao::insert
predicates |
public |
inherited from |
Insert the given Entity
With $insertID set to false (this is the default), the ID of the Entity (if any) will be ignored. Returns an Entity equal to the given Entity with the new ID.
In order to be able to reconstruct a table, the ID of the Entity can be inserted as well. Set $insertID to true to achieve this.
public function insert(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
Parameter #1 [ <optional> bool $insertID = false ]
): Entity
NodeDao::insertBatch
predicates |
public |
inherited from |
Insert the Entities from the given array
The ID of the Entity (if any) will be ignored. Returns an array of Entities equal to the given Entities with new IDs and ID as array key. This default behaviour can be altered by providing a closure that receives each inserted entity and decides what key will be returned:
$func = function(Entity $entity): int {
return $entity->getID();
};
In order to be able to reconstruct a table, the ID of the Entities can be inserted as well. Set $insertID to true to achieve this.
public function insertBatch(
Parameter #0 [ <required> array $entity_array ]
Parameter #1 [ <optional> ?Closure $func = NULL ]
Parameter #2 [ <optional> bool $insertID = false ]
): array
NodeDao::update
predicates |
public |
inherited from |
Update the given Entity
public function update(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
): int
NodeDao::updateBatch
predicates |
public |
inherited from |
Update the Entities in the given array
public function updateBatch(
Parameter #0 [ <required> array $entity_array ]
): int
NodeDao::delete
predicates |
public |
inherited from |
Delete the row with the given ID
public function delete(
Parameter #0 [ <required> int $ID ]
): int
NodeDao::deleteBatch
predicates |
public |
inherited from |
Delete rows with the given IDs
public function deleteBatch(
Parameter #0 [ <required> array $ids ]
): int
NodeDao::select
predicates |
public |
inherited from |
Fetch the Entity with the given ID
public function select(
Parameter #0 [ <required> int $ID ]
): ?Entity
NodeDao::selectBatch
predicates |
public |
inherited from |
Select Entities with the given IDs
The returned Entity[] array has Entity IDs as keys.
public function selectBatch(
Parameter #0 [ <required> array $ids ]
): array
NodeDao::deleteWhere
predicates |
public |
inherited from |
Delete Entity rows with a where-clause
DELETE FROM %table_name% WHERE %expression%
public function deleteWhere(
Parameter #0 [ <required> string $where_clause ]
): int
NodeDao::selectWhere
predicates |
public |
inherited from |
Select Entities with a where-clause
SELECT FROM %table_name% WHERE %expression% LIMIT %offset%, %limit%;
The optional $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.
$func = function(Entity $entity): int {
return $entity->getID();
};
public function selectWhere(
Parameter #0 [ <required> string $where_clause ]
Parameter #1 [ <optional> int $offset = 0 ]
Parameter #2 [ <optional> int $limit = bhenk\msdata\abc\PHP_INT_MAX ]
Parameter #3 [ <optional> ?Closure $func = NULL ]
): array
NodeDao::selectSql
predicates |
public |
inherited from |
Select Entities with a sql statement
The optional $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.
$func = function(Entity $entity): int {
return $entity->getID();
};
If the $sql selects not all fields from the designated table or selects from tables other than the designated, the result is unpredictable.
public function selectSql(
Parameter #0 [ <required> string $sql ]
Parameter #1 [ <optional> ?Closure $func = NULL ]
): array
NodeDao::execute
predicates |
public |
inherited from |
Execute the given query
public function execute(
Parameter #0 [ <required> string $sql ]
): array|bool
Sat, 01 Jul 2023 13:02:23 +0000
NodeDo
namespace |
bhenk\msdata\node |
predicates |
Cloneable | Instantiable |
implements |
|
extends |
|
hierarchy |
Constructor
NodeDo::__construct
predicates |
public | constructor |
public function __construct(
Parameter #0 [ <optional> ?int $ID = NULL ]
Parameter #1 [ <optional> ?int $parent_id = NULL ]
Parameter #2 [ <optional> ?string $name = NULL ]
Parameter #3 [ <optional> ?string $alias = NULL ]
Parameter #4 [ <optional> ?string $nature = NULL ]
Parameter #5 [ <optional> bool $public = true ]
Parameter #6 [ <optional> float $estimate = 0.0 ]
)
Methods
NodeDo::getParentId
predicates |
public |
public function getParentId(): ?int
NodeDo::setParentId
predicates |
public |
public function setParentId(
Parameter #0 [ <required> ?int $parent_id ]
): void
NodeDo::getName
predicates |
public |
public function getName(): ?string
NodeDo::setName
predicates |
public |
public function setName(
Parameter #0 [ <required> ?string $name ]
): void
NodeDo::getAlias
predicates |
public |
public function getAlias(): ?string
NodeDo::setAlias
predicates |
public |
public function setAlias(
Parameter #0 [ <required> ?string $alias ]
): void
NodeDo::getNature
predicates |
public |
public function getNature(): ?string
NodeDo::setNature
predicates |
public |
public function setNature(
Parameter #0 [ <required> ?string $nature ]
): void
NodeDo::isPublic
predicates |
public |
public function isPublic(): bool
NodeDo::setPublic
predicates |
public |
public function setPublic(
Parameter #0 [ <required> bool $public ]
): void
NodeDo::getEstimate
predicates |
public |
public function getEstimate(): float
NodeDo::setEstimate
predicates |
public |
public function setEstimate(
Parameter #0 [ <required> float $estimate ]
): void
NodeDo::clone
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Create an Entity that equals this Entity
The newly created Entity gets the given ID or no ID if $ID is null.
@inheritdoc
from method EntityInterface::clone
public function clone(
Parameter #0 [ <optional> ?int $ID = NULL ]
): Entity
NodeDo::toArray
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Express the properties of this Entity in an array
The returned array should be in such order that it can be fet to the static method EntityInterface::fromArray().
@inheritdoc
from method EntityInterface::toArray
see also
public function toArray(): array
NodeDo::getParents
predicates |
public |
inherited from |
Get the (Reflection) parents of this Entity in reverse order
class A extends Entity
class B extends A
returned array = [Entity-Reflection, A-Reflection, B-Reflection]
public function getParents(): array
NodeDo::fromArray
predicates |
public | static |
implements |
|
inherited from |
Create a new Entity
The order of the given array should be parent-first, i.e.:
class A extends Entity
class B extends A
In __construct(), toArray() and fromArray() functions, properties/parameters have the order:
ID, {props of A}, {props of B}
@inheritdoc
Create a new Entity from an array of properties
The given array should have the same order as the one gotten from EntityInterface::toArray().
@inheritdoc
from method EntityInterface::fromArray
public static function fromArray(
Parameter #0 [ <required> array $arr ]
): static
NodeDo::isSame
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Test is same function
The given Entity is similar to this Entity if all properties, including ID, are equal.
@inheritdoc
from method EntityInterface::isSame
public function isSame(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
): bool
NodeDo::equals
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Test equals function
The given Entity equals this Entity if all properties, except ID, are equal.
@inheritdoc
from method EntityInterface::equals
public function equals(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
): bool
NodeDo::getID
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Get the ID of this Entity or null if it has no ID
@inheritdoc
from method EntityInterface::getID
public function getID(): ?int
NodeDo::__toString
predicates |
public |
implements |
|
inherited from |
String representation of this Entity
public function __toString(): string
Sat, 01 Jul 2023 13:02:23 +0000
Sat, 01 Jul 2023 13:02:23 +0000
user
Depends on |
Dependency invoked by |
---|---|
PersonDao
namespace |
bhenk\msdata\user |
predicates |
Cloneable | Instantiable |
extends |
|
hierarchy |
Methods
PersonDao::getDataObjectName
predicates |
public |
implements |
public function getDataObjectName(): string
PersonDao::getTableName
predicates |
public |
implements |
public function getTableName(): string
PersonDao::dropTable
predicates |
public |
inherited from |
Drop table if it exists
Tries to drop the table with the name returned by AbstractDao::getTableName.
public function dropTable(): bool
PersonDao::createTable
predicates |
public |
inherited from |
Create a table in the database
The statement used is the one from getCreateTableStatement.
public function createTable(
Parameter #0 [ <optional> bool $drop = false ]
): int
PersonDao::getCreateTableStatement
predicates |
public |
inherited from |
Produces a minimal CreateTableStatement
CREATE TABLE IF NOT EXISTS `%table_name%`
(
`ID` INT NOT NULL AUTO_INCREMENT,
`%int_prop%` INT,
`%string_prop%` VARCHAR(255),
`%bool_prop%` BOOLEAN,
`%float_prop%` FLOAT,
PRIMARY KEY (`ID`)
);
In the above %xyz% is placeholder for table name or property name. Notice that string type parameters have a limited length of 255 characters.
Subclasses may override. The table MUST have the same name as the one returned by the method getTableName.
public function getCreateTableStatement(): string
PersonDao::insert
predicates |
public |
inherited from |
Insert the given Entity
With $insertID set to false (this is the default), the ID of the Entity (if any) will be ignored. Returns an Entity equal to the given Entity with the new ID.
In order to be able to reconstruct a table, the ID of the Entity can be inserted as well. Set $insertID to true to achieve this.
public function insert(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
Parameter #1 [ <optional> bool $insertID = false ]
): Entity
PersonDao::insertBatch
predicates |
public |
inherited from |
Insert the Entities from the given array
The ID of the Entity (if any) will be ignored. Returns an array of Entities equal to the given Entities with new IDs and ID as array key. This default behaviour can be altered by providing a closure that receives each inserted entity and decides what key will be returned:
$func = function(Entity $entity): int {
return $entity->getID();
};
In order to be able to reconstruct a table, the ID of the Entities can be inserted as well. Set $insertID to true to achieve this.
public function insertBatch(
Parameter #0 [ <required> array $entity_array ]
Parameter #1 [ <optional> ?Closure $func = NULL ]
Parameter #2 [ <optional> bool $insertID = false ]
): array
PersonDao::update
predicates |
public |
inherited from |
Update the given Entity
public function update(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
): int
PersonDao::updateBatch
predicates |
public |
inherited from |
Update the Entities in the given array
public function updateBatch(
Parameter #0 [ <required> array $entity_array ]
): int
PersonDao::delete
predicates |
public |
inherited from |
Delete the row with the given ID
public function delete(
Parameter #0 [ <required> int $ID ]
): int
PersonDao::deleteBatch
predicates |
public |
inherited from |
Delete rows with the given IDs
public function deleteBatch(
Parameter #0 [ <required> array $ids ]
): int
PersonDao::select
predicates |
public |
inherited from |
Fetch the Entity with the given ID
public function select(
Parameter #0 [ <required> int $ID ]
): ?Entity
PersonDao::selectBatch
predicates |
public |
inherited from |
Select Entities with the given IDs
The returned Entity[] array has Entity IDs as keys.
public function selectBatch(
Parameter #0 [ <required> array $ids ]
): array
PersonDao::deleteWhere
predicates |
public |
inherited from |
Delete Entity rows with a where-clause
DELETE FROM %table_name% WHERE %expression%
public function deleteWhere(
Parameter #0 [ <required> string $where_clause ]
): int
PersonDao::selectWhere
predicates |
public |
inherited from |
Select Entities with a where-clause
SELECT FROM %table_name% WHERE %expression% LIMIT %offset%, %limit%;
The optional $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.
$func = function(Entity $entity): int {
return $entity->getID();
};
public function selectWhere(
Parameter #0 [ <required> string $where_clause ]
Parameter #1 [ <optional> int $offset = 0 ]
Parameter #2 [ <optional> int $limit = bhenk\msdata\abc\PHP_INT_MAX ]
Parameter #3 [ <optional> ?Closure $func = NULL ]
): array
PersonDao::selectSql
predicates |
public |
inherited from |
Select Entities with a sql statement
The optional $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.
$func = function(Entity $entity): int {
return $entity->getID();
};
If the $sql selects not all fields from the designated table or selects from tables other than the designated, the result is unpredictable.
public function selectSql(
Parameter #0 [ <required> string $sql ]
Parameter #1 [ <optional> ?Closure $func = NULL ]
): array
PersonDao::execute
predicates |
public |
inherited from |
Execute the given query
public function execute(
Parameter #0 [ <required> string $sql ]
): array|bool
Sat, 01 Jul 2023 13:02:23 +0000
PersonDo
namespace |
bhenk\msdata\user |
predicates |
Cloneable | Instantiable |
implements |
|
extends |
|
hierarchy |
Constructor
PersonDo::__construct
predicates |
public | constructor |
public function __construct(
Parameter #0 [ <optional> ?int $ID = NULL ]
Parameter #1 [ <optional> ?string $first_name = NULL ]
Parameter #2 [ <optional> ?string $prefixes = NULL ]
Parameter #3 [ <optional> ?string $last_name = NULL ]
Parameter #4 [ <optional> ?string $email = NULL ]
Parameter #5 [ <optional> ?int $knows = NULL ]
)
Methods
PersonDo::getKnows
predicates |
public |
public function getKnows(): ?int
PersonDo::setKnows
predicates |
public |
public function setKnows(
Parameter #0 [ <required> ?int $knows ]
): void
PersonDo::getFirstName
predicates |
public |
inherited from |
public function getFirstName(): ?string
PersonDo::setFirstName
predicates |
public |
inherited from |
public function setFirstName(
Parameter #0 [ <required> ?string $first_name ]
): void
PersonDo::getPrefixes
predicates |
public |
inherited from |
public function getPrefixes(): ?string
PersonDo::setPrefixes
predicates |
public |
inherited from |
public function setPrefixes(
Parameter #0 [ <required> ?string $prefixes ]
): void
PersonDo::getLastName
predicates |
public |
inherited from |
public function getLastName(): ?string
PersonDo::setLastName
predicates |
public |
inherited from |
public function setLastName(
Parameter #0 [ <required> ?string $last_name ]
): void
PersonDo::getEmail
predicates |
public |
inherited from |
public function getEmail(): ?string
PersonDo::setEmail
predicates |
public |
inherited from |
public function setEmail(
Parameter #0 [ <required> ?string $email ]
): void
PersonDo::clone
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Create an Entity that equals this Entity
The newly created Entity gets the given ID or no ID if $ID is null.
@inheritdoc
from method EntityInterface::clone
public function clone(
Parameter #0 [ <optional> ?int $ID = NULL ]
): Entity
PersonDo::toArray
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Express the properties of this Entity in an array
The returned array should be in such order that it can be fet to the static method EntityInterface::fromArray().
@inheritdoc
from method EntityInterface::toArray
see also
public function toArray(): array
PersonDo::getParents
predicates |
public |
inherited from |
Get the (Reflection) parents of this Entity in reverse order
class A extends Entity
class B extends A
returned array = [Entity-Reflection, A-Reflection, B-Reflection]
public function getParents(): array
PersonDo::fromArray
predicates |
public | static |
implements |
|
inherited from |
Create a new Entity
The order of the given array should be parent-first, i.e.:
class A extends Entity
class B extends A
In __construct(), toArray() and fromArray() functions, properties/parameters have the order:
ID, {props of A}, {props of B}
@inheritdoc
Create a new Entity from an array of properties
The given array should have the same order as the one gotten from EntityInterface::toArray().
@inheritdoc
from method EntityInterface::fromArray
public static function fromArray(
Parameter #0 [ <required> array $arr ]
): static
PersonDo::isSame
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Test is same function
The given Entity is similar to this Entity if all properties, including ID, are equal.
@inheritdoc
from method EntityInterface::isSame
public function isSame(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
): bool
PersonDo::equals
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Test equals function
The given Entity equals this Entity if all properties, except ID, are equal.
@inheritdoc
from method EntityInterface::equals
public function equals(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
): bool
PersonDo::getID
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Get the ID of this Entity or null if it has no ID
@inheritdoc
from method EntityInterface::getID
public function getID(): ?int
PersonDo::__toString
predicates |
public |
implements |
|
inherited from |
String representation of this Entity
public function __toString(): string
Sat, 01 Jul 2023 13:02:23 +0000
UserDao
namespace |
bhenk\msdata\user |
predicates |
Cloneable | Instantiable |
extends |
|
hierarchy |
Methods
UserDao::getDataObjectName
predicates |
public |
implements |
public function getDataObjectName(): string
UserDao::getTableName
predicates |
public |
implements |
public function getTableName(): string
UserDao::dropTable
predicates |
public |
inherited from |
Drop table if it exists
Tries to drop the table with the name returned by AbstractDao::getTableName.
public function dropTable(): bool
UserDao::createTable
predicates |
public |
inherited from |
Create a table in the database
The statement used is the one from getCreateTableStatement.
public function createTable(
Parameter #0 [ <optional> bool $drop = false ]
): int
UserDao::getCreateTableStatement
predicates |
public |
inherited from |
Produces a minimal CreateTableStatement
CREATE TABLE IF NOT EXISTS `%table_name%`
(
`ID` INT NOT NULL AUTO_INCREMENT,
`%int_prop%` INT,
`%string_prop%` VARCHAR(255),
`%bool_prop%` BOOLEAN,
`%float_prop%` FLOAT,
PRIMARY KEY (`ID`)
);
In the above %xyz% is placeholder for table name or property name. Notice that string type parameters have a limited length of 255 characters.
Subclasses may override. The table MUST have the same name as the one returned by the method getTableName.
public function getCreateTableStatement(): string
UserDao::insert
predicates |
public |
inherited from |
Insert the given Entity
With $insertID set to false (this is the default), the ID of the Entity (if any) will be ignored. Returns an Entity equal to the given Entity with the new ID.
In order to be able to reconstruct a table, the ID of the Entity can be inserted as well. Set $insertID to true to achieve this.
public function insert(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
Parameter #1 [ <optional> bool $insertID = false ]
): Entity
UserDao::insertBatch
predicates |
public |
inherited from |
Insert the Entities from the given array
The ID of the Entity (if any) will be ignored. Returns an array of Entities equal to the given Entities with new IDs and ID as array key. This default behaviour can be altered by providing a closure that receives each inserted entity and decides what key will be returned:
$func = function(Entity $entity): int {
return $entity->getID();
};
In order to be able to reconstruct a table, the ID of the Entities can be inserted as well. Set $insertID to true to achieve this.
public function insertBatch(
Parameter #0 [ <required> array $entity_array ]
Parameter #1 [ <optional> ?Closure $func = NULL ]
Parameter #2 [ <optional> bool $insertID = false ]
): array
UserDao::update
predicates |
public |
inherited from |
Update the given Entity
public function update(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
): int
UserDao::updateBatch
predicates |
public |
inherited from |
Update the Entities in the given array
public function updateBatch(
Parameter #0 [ <required> array $entity_array ]
): int
UserDao::delete
predicates |
public |
inherited from |
Delete the row with the given ID
public function delete(
Parameter #0 [ <required> int $ID ]
): int
UserDao::deleteBatch
predicates |
public |
inherited from |
Delete rows with the given IDs
public function deleteBatch(
Parameter #0 [ <required> array $ids ]
): int
UserDao::select
predicates |
public |
inherited from |
Fetch the Entity with the given ID
public function select(
Parameter #0 [ <required> int $ID ]
): ?Entity
UserDao::selectBatch
predicates |
public |
inherited from |
Select Entities with the given IDs
The returned Entity[] array has Entity IDs as keys.
public function selectBatch(
Parameter #0 [ <required> array $ids ]
): array
UserDao::deleteWhere
predicates |
public |
inherited from |
Delete Entity rows with a where-clause
DELETE FROM %table_name% WHERE %expression%
public function deleteWhere(
Parameter #0 [ <required> string $where_clause ]
): int
UserDao::selectWhere
predicates |
public |
inherited from |
Select Entities with a where-clause
SELECT FROM %table_name% WHERE %expression% LIMIT %offset%, %limit%;
The optional $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.
$func = function(Entity $entity): int {
return $entity->getID();
};
public function selectWhere(
Parameter #0 [ <required> string $where_clause ]
Parameter #1 [ <optional> int $offset = 0 ]
Parameter #2 [ <optional> int $limit = bhenk\msdata\abc\PHP_INT_MAX ]
Parameter #3 [ <optional> ?Closure $func = NULL ]
): array
UserDao::selectSql
predicates |
public |
inherited from |
Select Entities with a sql statement
The optional $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.
$func = function(Entity $entity): int {
return $entity->getID();
};
If the $sql selects not all fields from the designated table or selects from tables other than the designated, the result is unpredictable.
public function selectSql(
Parameter #0 [ <required> string $sql ]
Parameter #1 [ <optional> ?Closure $func = NULL ]
): array
UserDao::execute
predicates |
public |
inherited from |
Execute the given query
public function execute(
Parameter #0 [ <required> string $sql ]
): array|bool
Sat, 01 Jul 2023 13:02:23 +0000
UserDo
namespace |
bhenk\msdata\user |
predicates |
Cloneable | Instantiable |
implements |
|
extends |
|
hierarchy |
|
known subclasses |
A simple user
This line has Entity, OutOfBoundsException, Entity 3 links.
- A box of roses
with content
Constructor
UserDo::__construct
predicates |
public | constructor |
public function __construct(
Parameter #0 [ <optional> ?int $ID = NULL ]
Parameter #1 [ <optional> ?string $first_name = NULL ]
Parameter #2 [ <optional> ?string $prefixes = NULL ]
Parameter #3 [ <optional> ?string $last_name = NULL ]
Parameter #4 [ <optional> ?string $email = NULL ]
)
Methods
UserDo::getFirstName
predicates |
public |
public function getFirstName(): ?string
UserDo::setFirstName
predicates |
public |
public function setFirstName(
Parameter #0 [ <required> ?string $first_name ]
): void
UserDo::getPrefixes
predicates |
public |
public function getPrefixes(): ?string
UserDo::setPrefixes
predicates |
public |
public function setPrefixes(
Parameter #0 [ <required> ?string $prefixes ]
): void
UserDo::getLastName
predicates |
public |
public function getLastName(): ?string
UserDo::setLastName
predicates |
public |
public function setLastName(
Parameter #0 [ <required> ?string $last_name ]
): void
UserDo::getEmail
predicates |
public |
public function getEmail(): ?string
UserDo::setEmail
predicates |
public |
public function setEmail(
Parameter #0 [ <required> ?string $email ]
): void
UserDo::clone
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Create an Entity that equals this Entity
The newly created Entity gets the given ID or no ID if $ID is null.
@inheritdoc
from method EntityInterface::clone
public function clone(
Parameter #0 [ <optional> ?int $ID = NULL ]
): Entity
UserDo::toArray
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Express the properties of this Entity in an array
The returned array should be in such order that it can be fet to the static method EntityInterface::fromArray().
@inheritdoc
from method EntityInterface::toArray
see also
public function toArray(): array
UserDo::getParents
predicates |
public |
inherited from |
Get the (Reflection) parents of this Entity in reverse order
class A extends Entity
class B extends A
returned array = [Entity-Reflection, A-Reflection, B-Reflection]
public function getParents(): array
UserDo::fromArray
predicates |
public | static |
implements |
|
inherited from |
Create a new Entity
The order of the given array should be parent-first, i.e.:
class A extends Entity
class B extends A
In __construct(), toArray() and fromArray() functions, properties/parameters have the order:
ID, {props of A}, {props of B}
@inheritdoc
Create a new Entity from an array of properties
The given array should have the same order as the one gotten from EntityInterface::toArray().
@inheritdoc
from method EntityInterface::fromArray
public static function fromArray(
Parameter #0 [ <required> array $arr ]
): static
UserDo::isSame
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Test is same function
The given Entity is similar to this Entity if all properties, including ID, are equal.
@inheritdoc
from method EntityInterface::isSame
public function isSame(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
): bool
UserDo::equals
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Test equals function
The given Entity equals this Entity if all properties, except ID, are equal.
@inheritdoc
from method EntityInterface::equals
public function equals(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
): bool
UserDo::getID
predicates |
public |
implements |
|
inherited from |
@inheritdoc
Get the ID of this Entity or null if it has no ID
@inheritdoc
from method EntityInterface::getID
public function getID(): ?int
UserDo::__toString
predicates |
public |
implements |
|
inherited from |
String representation of this Entity
public function __toString(): string
Sat, 01 Jul 2023 13:02:23 +0000
Sat, 01 Jul 2023 13:02:23 +0000
zzz
Depends on |
Dependency invoked by |
---|---|
JoinDao
namespace |
bhenk\msdata\zzz |
predicates |
Cloneable | Instantiable |
extends |
|
hierarchy |
Methods
JoinDao::getDataObjectName
predicates |
public |
implements |
@inheritdoc
Get the fully qualified classname of the Entity this class provides access to
@inheritdoc
from method AbstractDao::getDataObjectName
public function getDataObjectName(): string
JoinDao::getTableName
predicates |
public |
implements |
@inheritdoc
Get the name of the table that will store the Entity this class provides access to
@inheritdoc
from method AbstractDao::getTableName
public function getTableName(): string
JoinDao::selectLeft
predicates |
public |
inherited from |
Select on left hand foreign key
public function selectLeft(
Parameter #0 [ <required> int $fk_left ]
): array
JoinDao::selectRight
predicates |
public |
inherited from |
Select on right hand foreign key
public function selectRight(
Parameter #0 [ <required> int $fk_right ]
): array
JoinDao::updateLeftJoin
predicates |
public |
inherited from |
Update Joins with a common FK_LEFT
This method deletes deleted Joins; updates existing Joins and inserts new Joins.
Side effect: the common $fk_left will be set on all Joins.
public function updateLeftJoin(
Parameter #0 [ <required> int $fk_left ]
Parameter #1 [ <required> array $joins ]
): array
JoinDao::updateRightJoin
predicates |
public |
inherited from |
Update Joins with a common FK_RIGHT
This method deletes deleted Joins; updates existing Joins and inserts new Joins.
Side effect: the common $fk_right will be set on all Joins.
public function updateRightJoin(
Parameter #0 [ <required> int $fk_right ]
Parameter #1 [ <required> array $joins ]
): array
JoinDao::dropTable
predicates |
public |
inherited from |
Drop table if it exists
Tries to drop the table with the name returned by AbstractDao::getTableName().
public function dropTable(): bool
JoinDao::createTable
predicates |
public |
inherited from |
Create a table in the database
The statement used is the one from AbstractDao::getCreateTableStatement().
public function createTable(
Parameter #0 [ <optional> bool $drop = false ]
): int
JoinDao::getCreateTableStatement
predicates |
public |
inherited from |
Produces a minimal CreateTableStatement
CREATE TABLE IF NOT EXISTS `%table_name%`
(
`ID` INT NOT NULL AUTO_INCREMENT,
`%int_prop%` INT,
`%string_prop%` VARCHAR(255),
`%bool_prop%` BOOLEAN,
`%float_prop%` FLOAT,
PRIMARY KEY (`ID`)
);
In the above %xyz% is placeholder for table name or property name. Notice that string type parameters have a limited length of 255 characters.
Subclasses may override. The table MUST have the same name as the one returned by the method AbstractDao::getTableName().
public function getCreateTableStatement(): string
JoinDao::insert
predicates |
public |
inherited from |
Insert the given Entity
With $insertID set to false (this is the default), the ID of the Entity (if any) will be ignored. Returns an Entity equal to the given Entity with the new ID.
In order to be able to reconstruct a table, the ID of the Entity can be inserted as well. Set $insertID to true to achieve this.
public function insert(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
Parameter #1 [ <optional> bool $insertID = false ]
): Entity
JoinDao::insertBatch
predicates |
public |
inherited from |
Insert the Entities from the given array
The ID of the Entity (if any) will be ignored. Returns an array of Entities equal to the given Entities with new IDs and ID as array key. This default behaviour can be altered by providing a closure that receives each inserted entity and decides what key will be returned:
$func = function(Entity $entity): int {
return $entity->getID();
};
In order to be able to reconstruct a table, the ID of the Entities can be inserted as well. Set $insertID to true to achieve this.
public function insertBatch(
Parameter #0 [ <required> array $entity_array ]
Parameter #1 [ <optional> ?Closure $func = NULL ]
Parameter #2 [ <optional> bool $insertID = false ]
): array
JoinDao::update
predicates |
public |
inherited from |
Update the given Entity
public function update(
Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
): int
JoinDao::updateBatch
predicates |
public |
inherited from |
Update the Entities in the given array
public function updateBatch(
Parameter #0 [ <required> array $entity_array ]
): int
JoinDao::delete
predicates |
public |
inherited from |
Delete the row with the given ID
public function delete(
Parameter #0 [ <required> int $ID ]
): int
JoinDao::deleteBatch
predicates |
public |
inherited from |
Delete rows with the given IDs
public function deleteBatch(
Parameter #0 [ <required> array $ids ]
): int
JoinDao::select
predicates |
public |
inherited from |
Fetch the Entity with the given ID
public function select(
Parameter #0 [ <required> int $ID ]
): ?Entity
JoinDao::selectBatch
predicates |
public |
inherited from |
Select Entities with the given IDs
The returned Entity[] array has Entity IDs as keys.
public function selectBatch(
Parameter #0 [ <required> array $ids ]
): array
JoinDao::deleteWhere
predicates |
public |
inherited from |
Delete Entity rows with a where-clause
DELETE FROM %table_name% WHERE %expression%
public function deleteWhere(
Parameter #0 [ <required> string $where_clause ]
): int
JoinDao::selectWhere
predicates |
public |
inherited from |
Select Entities with a where-clause
SELECT FROM %table_name% WHERE %expression% LIMIT %offset%, %limit%;
The optional $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.
$func = function(Entity $entity): int {
return $entity->getID();
};
public function selectWhere(
Parameter #0 [ <required> string $where_clause ]
Parameter #1 [ <optional> int $offset = 0 ]
Parameter #2 [ <optional> int $limit = bhenk\msdata\abc\PHP_INT_MAX ]
Parameter #3 [ <optional> ?Closure $func = NULL ]
): array
JoinDao::selectSql
predicates |
public |
inherited from |
Select Entities with a sql statement
The optional $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.
$func = function(Entity $entity): int {
return $entity->getID();
};
If the $sql selects not all fields from the designated table or selects from tables other than the designated, the result is unpredictable.
public function selectSql(
Parameter #0 [ <required> string $sql ]
Parameter #1 [ <optional> ?Closure $func = NULL ]
): array
JoinDao::execute
predicates |
public |
inherited from |
Execute the given query
public function execute(
Parameter #0 [ <required> string $sql ]
): array|bool
Sat, 01 Jul 2023 13:02:23 +0000
Sat, 01 Jul 2023 13:02:23 +0000
Sat, 01 Jul 2023 13:02:22 +0000