evolutionphp/database
Composer 安装命令:
composer require evolutionphp/database
包简介
Codeigniter 3 standalone database (MySQL).
关键字:
README 文档
README
Codeigniter 3 standalone database (MySQL).
Installation
Use Composer to install Logger into your project:
composer require evolutionphp/database
Configuration
- Set configuration var with details of database
$data = array( 'hostname' => 'localhost', //Database Hostname 'username' => 'root', //Database Username 'password' => 'root', //Database Password 'database' => 'mydb', //Database Name 'table_prefix' => '', //Table prefix 'char_set' => 'utf8mb4', //Database chart set 'dbcollat' => 'utf8mb4_bin', //Database collation 'port' => '', //Enter if you know the port number, otherwise leave empty );
- Initialize class
$db = \EvolutionPHP\Database\Database::connect($data);
Call instance
If you already initialize the Database class, then you can call an instance
$db = \EvolutionPHP\Database\Database::connect();
Usage Examples
Standard Query With Multiple Results (Object Version)
This is optional, you can save logs of errors. For params of logger go to SimpleLogger
$query = $db->query('SELECT name, title, email FROM my_table'); foreach ($query->result() as $row) { echo $row->title; echo $row->name; echo $row->email; } echo 'Total Results: ' . $query->num_rows();
Standard Query With Single Result
$query = $this->db->query('SELECT name FROM my_table LIMIT 1'); $row = $query->row(); echo $row->name;
Standard Insert
$sql = "INSERT INTO mytable (title, name) VALUES (".$this->db->escape($title).", ".$this->db->escape($name).")"; $this->db->query($sql); echo $this->db->affected_rows();
Query Builder Insert
$data = array( 'title' => $title, 'name' => $name, 'date' => $date ); $this->db->insert('mytable', $data); // Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
For more information visit CodeIgniter3 Query Builder
Database Manipulation
The Database Forge Class contains methods that help you manage your database.
Initializing the Forge Class
$forge = new \EvolutionPHP\Database\Library\Forge($db);
Creating a table Fields are created via an associative array. Within the array you must include a ‘type’ key that relates to the datatype of the field. For example, INT, VARCHAR, TEXT, etc. Many datatypes (for example VARCHAR) also require a ‘constraint’ key.
$fields = array( 'blog_id' => array( 'type' => 'INT', 'constraint' => 5, 'unsigned' => TRUE, 'auto_increment' => TRUE ), 'blog_title' => array( 'type' => 'VARCHAR', 'constraint' => '100', 'unique' => TRUE, ), 'blog_author' => array( 'type' =>'VARCHAR', 'constraint' => '100', 'default' => 'King of Town', ), 'blog_description' => array( 'type' => 'TEXT', 'null' => TRUE, ), ); $forge->add_field($fields);
Lets add keys
$forge->add_key('blog_id', TRUE); // gives PRIMARY KEY `blog_id` (`blog_id`) $forge->add_key('blog_name'); // gives KEY `blog_name` (`blog_name`)
Creating a table
$forge->create_table('table_name', TRUE); // gives CREATE TABLE IF NOT EXISTS table_name
For more information visit CodeIgniter3 Database Forge Class
Authors
This library was primarily developed by CodeIgniter 3 and modified by Andres M for standalone use.
evolutionphp/database 适用场景与选型建议
evolutionphp/database 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 03 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「mysql」 「codeigniter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 evolutionphp/database 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 evolutionphp/database 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 evolutionphp/database 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
The CodeIgniter Redis package
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-07