Skip to content

PHPCrud is a CRUD System designed to extend PHPWine functionality crud features. ( [ Optional ] Support since PHPWine v1.2.0.9 ++) compatible w/ wine (>=+v1.3.1)

License

Notifications You must be signed in to change notification settings

nielsoffice/PHPCrud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHPCrud

PHPCrud is a CRUD System designed to extend PHPWine functionality crud features.

Downloading PHPCrud Plugin:

// Download Plugin latest version 
 $ git clone https://github.com/nielsofficeofficial/PHPCrud

// Download specified version ( --branch tag ) --branch  v1.3.1.0 
 $ git clone https://github.com/nielsofficeofficial/PHPCrud --branch  v1.3.1.0 

Plugin PHPCrud Installation:

| - root folder
    | - vendor // generated by composer/Pkgist 
      | - PHPWine
          | - Plugins
             |- PHPCrud
          | - Wine
            | - src
            | - PHPWine.php
            | - prop.php
            | - LICENSE
            | - README.md
            | - composer.json
                    

Dependency Installation:

# Namespace / Dependency
use \PHPWineVanillaFlavour\Plugins\PHPCrud\Crud\Vanilla;

// Installing functions Vanilla since v1.3
new \PHPWineVanillaFlavour\Plugins\PHPCrud\Crud\Wine\VanillaApiWine;
new \PHPWineVanillaFlavour\Plugins\PHPCrud\Crud\Wine\VanillaWine;
new \PHPWineVanillaFlavour\Plugins\PHPCrud\Crud\Wine\VanillaCreate;
new \PHPWineVanillaFlavour\Plugins\PHPCrud\Crud\Wine\VanillaFetch;
new \PHPWineVanillaFlavour\Plugins\PHPCrud\Crud\Wine\VanillaUpdate;
new \PHPWineVanillaFlavour\Plugins\PHPCrud\Crud\Wine\VanillaDelete;
new \PHPWineVanillaFlavour\Plugins\PHPCrud\Crud\Wine\VanillaExtract;
# FLAG [ CRUD ] : (  Optional ) 
// Create       // Read          // Update      // Delete 
Vanilla::MAKE | Vanilla::FETCH | Vanilla::PUT | Vanilla::DELETE
 // Database Configuration
 $path > ./plugins/Crud/DBWine.php
  
 # HOST OR SERVER NAME
 const DB_HOST     = 'localhost';
 # HOST USER NAME
 const DB_USERNAME = 'root';
 # HOST PASSWORD
 const DB_PASSWORD = '';
 # DATBASE NAME
 const DB_NAME     = '';

-----------------------------------

 // New instance, Incase request to Join in single database connection
 $wineVanill = new Vanilla();
 // Establish public connection 
 $wine_db    = $new->wine_db();
# Create or Insert Data to Database

 if( $wine_db === false ) { die("ERROR: Could not connect. " . $wine_db->connect_error); }

 // Create incase insert bulk & join w/request last ID : 
 $wine = $wineVanilla->wine_creates( 'tbl_name' , [ 
     
    'col_name_1'  => '?', // !must be like : [ '?' ][ $debug : true ] " INSERT INTO tbl_name (col1, col2) VALUES ( ?,? ) ";
    'col_name_2'  => '?'

 ] , "ss" , array(
        
    $value_col_name_1,
    $value_col_name_2 
    
 ));
 
 echo ( !empty($wine) ) ? "Last_id : {$wine} Added new record! " : ''; 

 // OR Create single data
 $c = new Vanilla( Vanilla::MAKE, 'tbl_name', [ 
     
     'col_name_1'  => 'col_name_1_val',
     'col_name_2'  => 'col_name_2_val'
  
 ] , 'callBack' );

 function callBack( $new_record ) { if( $new_record ) { echo  " Added new record! "; }  }

 $wine_db->close();
# Read Data from Database

if( $wine_db === false ) { die("ERROR: Could not connect. " . $wine_db->connect_error); }

// Execution
function callBack( $read_datas ) { if( $read_datas ) { foreach( $read_datas as  $val ) { echo $val["col_name"]; }  } }

// Query
$wineVanilla->wine_fetch(  'tbl_name', [ 'name' ], 'callBack' );

// OR
$wine  = NEW Vanilla( Vanilla::FETCH, 'tbl_name',  [
     
    'col_name',
     
] , 'callBack' );

$wine_db->close();
# Update data from Database

if( $wine_db === false ) { die("ERROR: Could not connect. " . $wine_db->connect_error); }

function callBack( $updated ) { if( $updated ) { echo  " Updated record! "; } }

 // Update 
 $wineVanilla->wine_update( 'tbl_info', [
  
     'col_name'  => 'col_name_val',
     'condition' => [" WHERE id  = 107 "] 

 ] , 'callBack' );

 // OR
 $wine = new Vanilla( Vanilla::PUT, 'table_name', [

     'col_name'  => 'Value_1',
     'condition' => [" WHERE tabel_id  = 1 "] 
    
 ] , 'callBack' );

$wine_db->close();
# Delete data from Database
if( $wine_db === false ) { die("ERROR: Could not connect. " . $wine_db->connect_error); }

function callBack( $deleted ) { if( $deleted ) { echo  " Deleted record! "; } }

// col_name OR ( * ) if selected all data
// empty table run with [ 'mixed' ]
$wineVanilla->wine_delete( '', [
  
     'table_name',
     'condition' => [" WHERE id  = 107 "] 

 ] , 'callBack' );

// OR
$useWine = new Vanilla( Vanilla::DELETE, '', [

    'table_name',
    'condition' => [" WHERE id  = 1 "] 
    
] , 'callBack' );

$wine_db->close();
  /**
   * Defined : multi server or switch to databases
   * @since wine v1.3.1.1
   * @since vanilla v1.3.0.0
   * @since 04.30.2022
   **/ 
 wine_multi_server( object $db , vanilla|string $flag, array $method = [] );
  
 // Incase of Create 
 wine_multi_server( object $db , Vanilla::MAKE, [ 'query' => [] , 'dataType' => '', 'values' => [] debug => false ] );
 
 // Incase get inserted last id 
 $wine_multi_db = wine_multi_server( object $db , Vanilla::MAKE, [ 'query' => [] , 'dataType' => '', 'values' => [] debug => false ] );
  
 echo $wine_multi_db ?? "Sucessfull inserted last ID ".$wine_multi_db ;
   
   
 // Incase of Read 
 wine_multi_server( object $db , Vanilla::FETCH, [ 'query' => [] , 'fetch_request' => function() { ... }, debug => false ] );
 
 // Incase of Update 
 wine_multi_server( object $db , Vanilla::PUT, [ 'query' => [] , 'put_request' => function() { ... }, debug => false ] );
 
 // Incase of Delete 
 wine_multi_server( object $db , Vanilla::DELETE, [ 'query' => [] , 'delete_request' => function() { ... }, debug => false ] );
 
  /**
   * Defined: Incase of Create Multiple DB or switch
   * @since wine v1.3.1.1
   * @since vanilla v1.3.0.0
   * @since 04.30.2022
   **/ 
  if(isset($_REQUEST['insertData']) == true ) {

     if( $wine_create = $this->vanilla->wine_multi_server( new mysqli('localhost','root','','multiserver'), $this->vanilla::MAKE, ['query' => [ 
        
         'mixed' => [' INSERT INTO crud ( multi_name , multi_mobile , multi_email ) VALUES ( ?,?,? ); ']
                  
        ], 'dataType' => 'sss', 'values'=> array(
                      
         trim($_POST['friend_name'])   ?? '',
         trim($_POST['friend_mobile']) ?? '',
         trim($_POST['friend_email'])  ?? ''
              
         ), 'debug' => false ] ) ) {
          
          $_SESSION['create'] = "Last_id : " . $wine_create . " Added new record! ";
                
          header("location: vanilla-crud-multi.php?create-succesfully"); 
       } 

    }
  /**
   * Defined: Incase of Read Multiple DB or switch
   * @since wine v1.3.1.1
   * @since vanilla v1.3.0.0
   * @since 04.30.2022
   **/ 
     $this->read = $this->vanilla->wine_multi_server(new mysqli('localhost','root','','multiserver'), $this->vanilla::FETCH, [ 'query' => [ 
        
            'mixed' =>  [ "SELECT * FROM  crud ORDER BY id DESC LIMIT 3 " ]
                 
          ], 'fetch_request' => function( $read )  {  
                  
               $friends = array(); if( $read )  { 
                 
                foreach ($read as $value) {  
                   
                   $friends[] = ELEM('tr', [ CHILD => [
                  
                       ['td', VALUE => [ $value["multi_name"] ]   ],
                       ['td', VALUE => [ $value["multi_mobile"] ] ],
                       ['td', VALUE => [ $value["multi_email"]  ] ],
                       ['th', VALUE => [ ELEM('a', ELEM('i','', [['class','aria-hidden'],['fa fa-pencil','true']]) ,[['href'],['vanilla-crud-multi.php?edit='.$value["id"] .'']]) ]  ],
                       ['th', VALUE => [ ELEM('a', ELEM('i','', [['class','aria-hidden'],['fa fa-trash' ,'true']]) ,[['href'],['vanilla-crud-multi.php?delete='.$value["id"] .'']])  ]  ] 
                    
                      ]
                    
                    ]);
                  
               }  return (array)  $friends ;
       
             } 
               
            return [];
              
          }, 'debug' => false ] );
          
          // execute
          echo $this->init->wine_extract($this->read);
  /**
   * Defined: Incase of edit/fetch Multiple DB or switch
   * @since wine v1.3.1.1
   * @since vanilla v1.3.0.0
   * @since 04.30.2022
   **/ 
   if (isset($_REQUEST['edit']) == true ) :
     
   $this->updateRequest  = true; 
         
   $id     = $_REQUEST['edit'];
         
   $friend = $this->vanilla->wine_multi_server(new mysqli('localhost','root','','multiserver'), $this->vanilla::FETCH, [ 'query' => [
            
      'mixed' => [" SELECT * FROM crud WHERE id = ". $id ] 
        
    ], 'fetch_request' => function ( $friend ) {
            
    if($friend) { foreach($friend as $val ) { return $val; } }

    }, 'debug' => false] );
       
     $this->friend_name    =  $friend['multi_name'];
     $this->friend_mobile  =  $friend['multi_mobile'];
     $this->friend_email   =  $friend['multi_email'];
     $this->friend_id      =  $id;
        
    endif;
  /**
   * Defined: Incase of Update Multiple DB or switch
   * @since wine v1.3.1.1
   * @since vanilla v1.3.0.0
   * @since 04.30.2022
   **/ 
   if(isset($_REQUEST['updateData']) == true ) :  
        
     $friend_name    = $_REQUEST['friend_name'];
     $friend_mobile  = $_REQUEST['friend_mobile'];
     $friend_email   = $_REQUEST['friend_email'];
        
     $this->vanilla->wine_multi_server(new mysqli('localhost','root','','multiserver'), $this->vanilla::PUT, [ 'query' => [
            
     'mixed' => [
             
        "UPDATE crud 
            SET `multi_name`   = '$friend_name', 
                `multi_mobile` = '$friend_mobile', 
                `multi_email`  = '$friend_email' 
            
          WHERE id = ".$_REQUEST['friend_id'] 
             
      ] 
     ],'put_request' => function( $do_update ) { if( $do_update ) {
  
      $_SESSION['update'] = 'Succesfully Friend Updated !';
    
      header("location: vanilla-crud-multi.php?update-succesfully");   
          
     }      
    
  } , 'debug' => false ] );

  endif;
  /**
   * Defined: Incase of Delete Multiple DB or switch
   * @since wine v1.3.1.1
   * @since vanilla v1.3.0.0
   * @since 04.30.2022
   **/
   if( isset($_REQUEST['delete']) == true ) :
   
     $deleted_friend   = $_REQUEST['delete'];
         
     $this->vanilla->wine_multi_server(new mysqli('localhost','root','','multiserver'), $this->vanilla::DELETE, [ 'query' => [
            
       'mixed' => [" DELETE  FROM crud  WHERE id  = ". $deleted_friend ] 

     ],'delete_request' => function( $do_update ) { if( $do_update ) {
     
     $_SESSION['delete'] = 'Succesfully Friend Deleted !';
       
     header("location: vanilla-crud-multi.php?delete-succesfully");   
             
    }      
       
  } , 'debug' => false ] );

endif;  
// Query incase of mixed 
$query = [ 'mixed' => [" DELETE FROM `tbl_name` WHERE `col_id` = 179; "] ] 

$useWine->wine_delete( null, $query , 'callBack' );

// Incase of Query debugging set $debug = true | last @param
$useWine->wine_delete( 'tbl_name', $query , 'callBack',  true );

# Registered array keys 
[ 'condition' ] && [ 'mixed' ]

# PHPCrud Flags
// Create
$wineCrud = new Vanilla(Vanilla::MAKE,   string $tbl_name = null , array $query = [] , mixed $callback = null, bool $debug = false );
// Read
$wineCrud = new Vanilla(Vanilla::FETCH,  string $tbl_name = null , array $query = [] , mixed $callback = null, bool $debug = false );
// Update
$wineCrud = new Vanilla(Vanilla::PUT,    string $tbl_name = null , array $query = [] , mixed $callback = null, bool $debug = false );
// Delete
$wineCrud = new Vanilla(Vanilla::DELETE, string $tbl_name = null , array $query = [] , mixed $callback = null, bool $debug = false );

PHPCrud-sample-data >
PHPCrud_RESTAPI-Template >


Thanks To:

Github : To allow me to upload my PHPWine plugin Vanilla Flavour to repository
php.net : To oppurtunity Develop web application using corePHP - PHPFrameworks

LICENSE BY MIT

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Would you like me to treat a cake and coffee ?
Become a donor, Because with you! We can build more...

Donate:
GCash : +639650332900
Paypal account: [email protected]



Thanks and good luck!