evolutionphp/database 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

evolutionphp/database

最新稳定版本:1.2

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

  1. 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
);
  1. 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.

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固