PHP Classes

PHP CRUD API Example: Example API to manipulate database table records

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 enough user ratingsTotal: 135 This week: 1All time: 9,293 This week: 42Up
Version License PHP version Categories
crud-php 1.0.0The PHP License5HTML, PHP 5, Databases
Description 

Author

This package provides an example API to manipulate database table records.

It provides a service class and other classes that implement the basic operations to create, retrieve, update, delete records from an example database table.

The package also provides view scripts that can display a Web interface to allow users to enter data and see the information of the database table that the service API class manipulates.

Picture of adriano123456
  Performance   Level  
Innovation award
Innovation award
Nominee: 1x

 

Example

<?php

require_once 'Autoloader.php';
require_once
'Helper.php';

/**
 * Instanciamento de classes
 */
$db = new Conn("localhost", "crud_php", "root", "");
$cliente = new Cliente();
$objCliente = new ServiceCliente($db, $cliente);

/*
 * Add controller CRUD
 */

if(isset($_POST['action'] )){
   
    if(
$_POST['action'] == 'save_cliente'){
       
       
$cliente->setId ($_POST['id' ])
                ->
setNome ($_POST['nome' ])
                ->
setEmail($_POST['email']);
       
        if(
$_POST['id'] > 0){
            print
$objCliente->update();
                   
        }else{
           
$id = $objCliente->save();
           
$rst = $objCliente->find($id);
            print
json_encode($rst[0]);
        }
       
    }
   
    if(
$_POST['action'] == 'delete_cliente'){
       
       
$cliente->setId($_POST['id']);
        print
$objCliente->delete();
       
    }
   
}elseif(
$_GET != NULL){
   
   
$rst = $objCliente->find($_GET['id']);
    echo
json_encode($rst[0]);
   
}else{
   
   
Template::header();
   
Template::getFormCliente();
   
Template::getCliente($objCliente->show());
   
Template::footer();
   
}



  Files folder image Files (23)  
File Role Description
Files folder imageapi (2 directories)
Files folder imagenbproject (2 files)
Files folder image_vendor (2 directories)
Plain text file Autoloader.php Class Class source
Plain text file Helper.php Class Class source
Accessible without login Plain text file index.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:135
This week:1
All time:9,293
This week:42Up