Download the PHP package lodev09/php-models without Composer
On this page you can find all versions of the php package lodev09/php-models. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lodev09/php-models
More information about lodev09/php-models
Files in lodev09/php-models
Package php-models
Short Description A PHP library that allows you to easily create and define your models using PDO.
License MIT
Homepage https://github.com/lodev09/php-models
Informations about the package php-models
PHP Models
A PHP library that allows you to easily create and define your models using PDO
Features
- PDO wrapper
FETCH_INTO
made easy- Model helper
Installation
Usage
DB.php
The main \Models\DB
class is a PDO wrapper used to make CRUD much easier. It is a forked code from the php-pdo-wrapper-class
Available CRUD methods
$db->insert($sql, $binds)
or$db->insert($table, $values)
$db->select($sql, $binds)
$db->row($sql, $binds)
(same withselect
but will return single row)$db->update($sql, $binds)
or$db->update('table', $values)
$db->delete($sql, $binds)
or$db->delete('table', $filters)
The default style is PDO::FETCH_OBJ
Example:
Model.php
The \Models\Model
class is a parent class that can be inherited to a Model class. Inheriting this class allows you to automatically map the result "row" into your model class (table). This class basically uses the PDO::FETC_INTO
style and made it easier for you. Here are the steps to link your table into a class:
-
Initiate the
\Models\DB
instance (see above) -
Create your model class. For example, a
User.php
class - Register your table to your custom class
Now, you can directly get the User
instance from a query. Example:
Feedback
All bugs, feature requests, pull requests, feedback, etc., are welcome. Visit my site at www.lodev09.com or email me at [email protected]
Credits
© 2018 - Coded by Jovanni Lo / @lodev09
License
Released under the MIT License. See LICENSE file.