定制 bhavik/pdo-mysql 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

bhavik/pdo-mysql

最新稳定版本:1.0.2

Composer 安装命令:

composer require bhavik/pdo-mysql

包简介

PHP PDO Library

README 文档

README

Simplified PHP PDO class for mysql database to manipulate records in tables. If you don't have database query knowledge, you can ues this class. This class also usefull for database experts too.

Let's look at how to use.

How to use

To use this class please import file called PDOMySQL.php then you have to create instance of this using below code

$db=new PDOMySQL("mysql:host=HOST;dbname=DATABASE_NAME","USERNAME","PASSWORD");

Select

To get all records from table

$db->from("TABLE_NAME")->get();

Geting only first row

$db->from("TABLE_NAME")->getOne();

Limited records

To fetch first 5 five records

$db->from("TABLE_NAME")->limit(5);

Limit method accepct only one required parameter. To fetch first few records pass only integer. we can pass start position by passing string argument like this "3,5", this will result in LIMIT 3,5. We can also pass array,below code also results the same

$db->from("TABLE_NAME")->limit(array(3,5));

WHERE condition

We can apply where condition to select,update or delete query by using this function. This method accepts two argument.Second argument is optional when you pass string in first argument.

#Produces column = "constraint"
$db->where("column","constraint");

#Produces column >= "constraint"
$db->where("column>=","constraint");

When we pass conditional operator at end of first argument, it applies same conditional operator to generated clause. Above clause can also be generated by passing array. When we pass array in first argument, second parameter get ignored.

#Produces column = "constraint"
$db->where(array("column"=>"constraint"));

#Produces column >= "constraint"
$db->where(array("column >="=>"constraint");

Advanced:

#Produces column1 = "constraint1" AND column2 = "constraint2" AND column3 = "constraint3"
$db->where(array(
            "column1" => "constraint1", 
            "column2" => "constraint2", 
            "column3" => "constraint3")
        );

#Produces column1 = "constraint1" OR column2 = "constraint2" OR column3 = "constraint3"
$db->where(array(
            "column1" => "constraint1", 
            "column2" => "constraint2", 
            "column3" => "constraint3", 
            "OR")
        );

#Produces column1 = "constraint1" AND (column2 = "constraint2" OR column3 = "constraint3")
$db->where(array(
            "column1"=>"constraint1",
            array(
                "column2"=>"constraint2",
                "column3"=>"constraint3",
                "OR")
        ));

UPDATE

This method accepts two arguments, first table name and second array of columns fields to be updated.

# Produces UPDATE table SET col1= "val1",col2= "val2"
$db->update("table",array("col1"=>"val1","col2"=>"val2"));

# Produces UPDATE table SET col1= "val1",col2= "val2" WHERE c1="v1" AND c2="v2"
$db->where(array("c1"=>"v1","c2"=>"v2"))->update("table",array("col1"=>"val1","col2"=>"val2"));

INSERT

This method accepts two arguments, first table name and second array of value to insert.

# Produces INSERT INTO table (col1,col2) VALUES("val1","val2")
$db->insert("table",array("col1"=>"val1","col2"=>"val2"));

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-09-29