bhavik/pdo-mysql

This package is abandoned and no longer maintained. No replacement package was suggested.

PHP PDO Library

Installs: 137

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 3

Forks: 3

Open Issues: 0

Type:package

1.0.2 2015-10-02 17:49 UTC

This package is not auto-updated.

Last update: 2020-06-11 15:19:55 UTC


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"));