PHP Classes

Wepesi PHP ORM Framework: Execute common SQL queries using object functions

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 62 All time: 10,455 This week: 39Up
Version License PHP version Categories
wepesi-orm 1.0.0The PHP License7Databases, Design Patterns, PHP 7
Description 

Author

This package can execute common SQL queries using object functions.

It provides classes with a fluent interface that allows developers to compose common queries using functions to set query parameters like table names, fields, field values, and condition clauses.

Currently, the main classes provide functions to execute SQL SELECT, INSERT, UPDATE AND DELETE queries.

It also provides functions that can:

- Return the count of table records

- Get the last table record identifier that results from the last insert query

- The last query execution error

- The number of table rows affected by the last query

Picture of Boss Ibrahim Mussa
  Performance   Level  
Name: Boss Ibrahim Mussa <contact>
Classes: 13 packages by
Country: Congo Congo
Age: ???
All time rank: 28851 in Congo Congo
Week rank: 20 Up1 in Congo Congo Equal
Innovation award
Innovation award
Nominee: 5x

Recommendations

What is the best PHP pdo mysql class?
PHP Project using PDO MySQL Class

Map database records to objects
Store and retrieve objects without writing native SQL again

Example

<?php
$db
=$db??[];
$field = [
   
"userid" => 1,
   
"message" => "hello from wepesi",
   
"datecreated" => date('Y-m-d H:i:s',strtotime("now"))
];
try {
   
$db->insert("message")->field($field)->result();
    if(
$db->error()){
        throw new \
Exception($db->error());
    }
   
var_dump(["last insert ID : "=>$db->lastId()]);
} catch (
Exception $e) {
   
var_dump($e->getMessage());
}



Details

Wepesi-ORM

this is a simple model of an ORM writeen in php. it can ben modified as you want.

OVERVIEW

this module as been develloped under this configuration. - server :wampserver 3.2.4 64bit - apache :2.3.33 - php :7.3.13 - phpmyadmin:5.0.4 - mysql :5.7.21

in case some solution and method are not available be sure to use a version clause to this setup.

INTRODUCTION

this model is just a simple wait you can implement your own ORM and design according to your need. hope it wiil be helpfull

INTEGRATION

METHODE

  • SELECT
    `get` method is corresponding to `SELECT` in sql. with this method you can request your database,
    to do a `select * from table_name` also you can add somme method to make it power as you are using `sql`.
    you can see and example bellow.
    $db=DB::getInstance();
    $req=$db->get('message')->result();
    
  • first of all, we creat an instance of the database by using our `DB` class. withc will allow us to interact with the `mySQL` database.
  • in the `get` method we have the first parameter witch is the table_name, call the `result()` methode to execute your `query`.
    the result can be store into a variable for other purpose.
    the coresponding sql is:
    SELECT * FROM message
    
    to be precise with your request
    
    $req=$db->get("message")->fields(['userid','message'])->where(['userid',"=",1])->result(); var_dump($req);
    the corresponding `SQL`
    
    SELECT userid,message FROM message WHERE userid=1 this is not all, you can `LIMIT`, `OFFSET`,`groupBY`,`orderBy`,`ASC`,`DESC` for more detail, checkout the examole file on the test folder.
  • INSERT
    `insert` is used to record data. its can be used has you are using an an sql commande.
    checkout the example bellow
    $data = [
        "userid" => 2,
        "message" => "hello from wepesi",
        "datecreated" => Date('Y-m-d H:i:s')
    ];
    try {
            $db->insert("message")->fields($data)->result();
            if ($this->db->error()) {
                throw new Exception("operation failed. check the error description");
            }
            var_dump($this->db->lastId());
    } catch (Exception $ex) {
        echo $ex->getMessage();
    }
    
  • before insert data, we create an data object with index key value. you will realised that, the object `data` we define the `key` correspond to the table fields and it value.
  • call the insert method, we define the table name, and we call the fields method where we pass the data object to perdom the query.
    the corresponding sql look like
    INSERT INTO message (`userid`,`message`,`datecreated`) VALUES (?,?,?)
    
    from that request you can request for the last id record on call the `lastId()` method.
  • DELETE
    `delete` when you need to delete a record, this is the module to use.
    try {
        $db->delete("message")->where(["id","=",16])->result();
        if ($this->db->error()) {
            throw new Exception("failed to delete data");
        }
        return true;
    } catch (Exception $ex) {
        echo $ex->getMessage();
    }
    
    corespondig sql is
    
    DELETE `message` WHERE `id`='16'
  • call where method to define the condition to delete a record.
  • QUERY 
    the `query` method is used in case you have specific query you want to execute, then you can use it. 
    try{
        $req = $this->db->query("select * from message join users on users.id=message.userid");
        if($req->error()){
            throw new Exception($req->error());
        }
        return $req->result();
    }catch(Exception $ex){
        echo $ex->getMessage();
    }
    
    the example bellow describe how it can be used. with the `query` method use the `result()` method to get the result.
  • hope you enjoy.

  Files folder image Files (20)  
File Role Description
Files folder imagedb (1 file)
Files folder imagesrc (8 files)
Files folder imagetest (6 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file index.php Aux. Auxiliary script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (20)  /  db  
File Role Description
  Accessible without login Plain text file wepesi_db.sql Data Auxiliary data

  Files folder image Files (20)  /  src  
File Role Description
  Plain text file DB.php Class Class source
  Plain text file DBField.php Class Class source
  Plain text file DBWhere.php Class Class source
  Plain text file DB_Insert.php Class Class source
  Plain text file DB_Q.php Class Class source
  Plain text file DB_Query.php Class Class source
  Plain text file DB_Select.php Class Class source
  Plain text file QueryTransactions.php Class Class source

  Files folder image Files (20)  /  test  
File Role Description
  Accessible without login Plain text file delete.php Example Example script
  Accessible without login Plain text file index.php Aux. Auxiliary script
  Accessible without login Plain text file insert.php Example Example script
  Accessible without login Plain text file query.php Example Example script
  Accessible without login Plain text file select.php Example Example script
  Accessible without login Plain text file update.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:62
This week:0
All time:10,455
This week:39Up