softon/mysqli-dbclass 问题修复 & 功能扩展

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

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

softon/mysqli-dbclass

最新稳定版本:v1.0.0

Composer 安装命令:

composer require softon/mysqli-dbclass

包简介

A simple Object Oriented approach for accessing Mysql Databases.

README 文档

README

MySQLi Database Class for PHP Developers

A simple Object Oriented approach for accessing Mysql Databases. This class will make your life easy while developing your products and saves a lot of time that is wasted while creating simple CRUD operations. This class also suports Transactions. Good Error Reporting and Debuging features. Additional quick commands that provide better security and ease of developing. Refer example.php for all the sample code.

This class is an enhanced version of PHP MySQL wrapper v3 by ricocheting.com. Hence it is compatible with the class. To use the enhanced MySQL Wrapper simply include the Database.class.php in your code and everything should work as before.

How to Setup

Before you start, edit the config.inc.php to match your database credentials. Then include the Class file and config file on the top of the code where you want to use the class as show below.


include_once('config.inc.php');
include_once('Database.php');

Create a DB object to interact with the class.


$db = new Database(DB_SERVER,DB_USER,DB_PASS,DB_DATABASE);

You are all set to run any query with this $db object. If you are inside a function or a another class you may call the obtain function to recover the $db object.


$db = new Database::obtain();

How to Use

//Simple Raw Query
$result = $db->query("SELECT * FROM authors")->fetch();

//Parametrised Query and fetch one Record
$result = $db->query("SELECT * FROM :table WHERE :name = ':value'",['table'=>'authors','name'=>'paperid','value'=>'P12206436'])->fetch();

//Parametrised Query and fetch all Records
$result_array = $db->query("SELECT * FROM :table WHERE :name = ':value'",['table'=>'authors','name'=>'paperid','value'=>'P12206436'])->fetch_all();

// Find a row by id and fetch
$result = $db->findById('authors',1);

// Find a row by column and fetch
$result = $db->findByCol('authors','paperid','P12206436');


// Count All rows in a table
$result = $db->count('authors');

// Count All rows in a table with condition
$result = $db->count('authors'," astatus='Approved'");

// Update a row
$result = $db->update('authors',['paperid'=>'SHIBU']," id = '1'");

// Update a row with parameter protection
$result = $db->update('authors',['paperid'=>'SHIBU','aname'=>'test','aorg'=>'test']," id = '1'",['paperid','aname']);

// Bulk Update a row with parameter protection without transaction
$result = $db->bulk_update('authors',array(
    1=> array('paperid'=>'SHIBU','aname'=>'test','aorg'=>'test'),
    2=> array('paperid'=>'SHIBU2','aname'=>'test2','aorg'=>'test2')
),['paperid','aname']);


// Bulk Update a row without parameter protection with transaction
$result = $db->bulk_update('authors',array(
    1=> array('paperid'=>'SHIBU','aname'=>'test','aorg'=>'test'),
    2=> array('paperid'=>'SHIBU2','aname'=>'test2','aorg'=>'test2')
),null,true);

// Insert Data
$result = $db->insert('authors',['paperid'=>rand(1234,99999),'aname'=>'Test Ing']);

// Bulk Insert with parameter protection with transaction
$result = $db->bulk_insert('authors',array(
    array('paperid'=>'SHIBU','aname'=>'test','aorg'=>'test'),
    array('paperid'=>'SHIBU2','aname'=>'test2','aorg'=>'test2')
),['paperid','aname'],true);


// Delete a record
$result = $db->delete('authors'," id=1 ");

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-07