vista-php/database
最新稳定版本:1.0.3
Composer 安装命令:
composer require vista-php/database
包简介
Database abstraction layer
README 文档
README
Introduction
Vista PHP Database module is a part of Vista PHP Framework, but can also be used as a stand alone ORM (Object Relational Mapper) for PHP. It is designed to simplify database manipulation and provide a secure way to interact with databases.
Getting Started
Installation
composer require vista-php/database
Configuration
The database configuration should be stored in the config/database.php file.
The file should return an array with the following keys:
DB_TYPE, DB_HOST, DB_NAME, DB_USER and DB_PASS
For SQLite:
return [ 'DB_TYPE' => 'sqlite', 'DB_NAME' => __DIR__ . '../database/database.sqlite', ];
For MySQL:
return [ 'DB_TYPE' => 'mysql', 'DB_NAME' => 'database', 'DB_HOST' => 'localhost', 'DB_USER' => 'root', 'DB_PASS' => 'root' ];
Usage
All you need to do is extend the Vista\Model\Model class in one of your model class
and define the table name, primary key, columns and relationship methods.
Example:
use Vista\Model\Model; class User extends Model { protected string $table = 'users'; protected string $primaryKey = 'id'; protected array $columns = ['id', 'name', 'username', 'password']; protected array $relationships = ['posts'] public function posts() { return Post::where('user_id', $this->id); } }
统计信息
- 总下载量: 70
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-19