1. Go to this page and download the library: Download iqomp/model library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
/**
* Construct new model object
* @param array DB connection options
* @param string $model Model name
* @param string $table Table name
* @param array $chains?
* @param array $q_field?
* @param array $connections
* @param array $read List of connection for read
* @param array $write List of connection for write
*/
__construct(array $options);
/**
* Count average value of field
* @param string $field the field sum total to average
* @param array $where Where condition
* @return float Average value of the column
*/
avg(string $field, array $where = []): float;
/**
* Count total rows in table
* @param array $where Where condition
* @return int Total row
*/
count(array $where = []): int;
/**
* Insert single data to database
* @param array $row Array column-value pair of data to insert
* @param bool $ignore Ignore error data already there
* @return int Last inserted id on success, null otherwise
*/
create(array $row, bool $ignore = false): ?int;
/**
* Insert many data at once
* @param array $rows List of array list data to insert
* @param bool $ignore Ignore exists data if possible
* @return boolean true on success false otherwise.
*/
createMany(array $rows, bool $ignore = false): bool;
/**
* Decrease multiple columns with condition
* @param array $fields List of field-value pair of column to decrease by value
* @param $where Where condition
*/
dec(array $fields, array $where = []): bool;
/**
* Escape string to use in raw query
* @param string $str String to escape
* @return escaped string
*/
escape(string $str): string;
/**
* Get single row from table
* @param array $where Where condition
* @param array $order Array list of field-direction pair of sort
* @return object if exists or null
*/
getOne(array $where = [], array $order = ['id' => false]): ?object;
/**
* Get multiple rows from database
* @param array $where Where condition
* @param int $rpp Result per page, default 0 which is all.
* @param int $page Page number, default 1.
* @param array $order Array list of field-direction pair of sort
* @return array list of object or empty array
*/
get(array $where = [], int $rpp = 0, int $page = 1, array $order = ['id' => false]): array;
/**
* Get connection object
* @param string $target Connection type target
* @return resource connection
*/
getConnection(string $target = 'read');
/**
* Get connection name in config that the model use for $target connection
* @param string $target Connection type target
* @return string connection config name
*/
getConnectionName(string $target = 'read'): ?string;
/**
* Get current connection database name
* @param string $target Connection type target
* @return string database name
*/
getDBName(string $target = 'read'): ?string;
/**
* Get the driver name used for this model
* @return string driver name
*/
getDriver(): ?string;
/**
* Get the model name of current model
* @return string model name
*/
getModel(): string;
/**
* Get the tabel name that this model handle
* @return string
*/
getTable(): string;
/**
* Increase multiple columns with condition
* @param array $fields List of field-value pair of column to increase by value
* @param $where Where condition
*/
inc(array $fields, array $where = []): bool;
/**
* Return last error accured
* @return string error message or null
*/
lastError(): ?string;
/**
* Return last id inserted to database
* @return int last inserted id, or null otherwise
*/
lastId(): ?int;
/**
* Return the most last executed query
* @return string if exists, null otherwise
*/
lastQuery(): ?string;
/**
* Get the maximum value of field from table
* @param string $field The field to process
* @param array $where Where condition
* @return int The max value of field.
*/
max(string $field, array $where = []): int;
/**
* Get the minimum value of field from table
* @param string $field THe field to process
* @param array $where Where condition
* @return int The smallest value of field.
*/
min(string $field, array $where = []): int;
/**
* Remove row from table
* @param array $where Where condition
* @return boolean true on success, false otherwise.
*/
remove(array $where = []): bool;
/**
* Update table
* @param array $fields List of field-value pair of data to update
* @param array $where Where condition.
* @return boolean true on success false otherwise.
*/
set(array $fields, array $where = []): bool;
/**
* Sum table single field.
* @param string $field The field to sum
* @param array $where Where conditon.
* @return int total sum of the field value.
*/
sum(string $field, array $where = []): int;
/**
* Truncate the table
* @param string $target Connection target
*/
truncate(string $target = 'write'): bool;
use Company\Project\Model\Product;
$id = Product::create($array);
$product = Product::getOne(['id'=>$id]);