PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Cesar D. Rodas   CRUD Class   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example
Class: CRUD Class
Generate pages to list and edit database records
Author: By
Last change:
Date: 16 years ago
Size: 3,583 bytes
 

Contents

Class file image Download
<?php
/*
***************************************************************************
* Copyright (C) 2007-2008 by Sixdegrees *
* cesar@sixdegrees.com.br *
* "Working with freedom" *
* http://www.sixdegrees.com.br *
* *
* Permission is hereby granted, free of charge, to any person obtaining *
* a copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to *
* the following conditions: *
* *
* The above copyright notice and this permission notice shall be *
* included in all copies or substantial portions of the Software. *
* *
* 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 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. *
***************************************************************************
*/
error_reporting( ~ E_NOTICE & E_ALL );
require(
"class/crud.php");
 

$info = array(
   
/**
     * Show column => visible on read
     * Insert hide => autoincrement value, the form doesn't display on create
     * update read only => this value couldn't be update
     */
   
'id' => array(CAPTION => 'ID', SHOWCOLUMN => true, INSERT_HIDE =>true, UPDATE_READ_ONLY => true),
   
/*
     *
     */
   
'name' => array(CAPTION => 'Name', SHOWCOLUMN=>true ),
   
/*
     *
     *
     */
   
'country' => array(CAPTION => 'Contry', TABLE => "table_2", ID => "countryId", TEXT => "countryName", SHOWCOLUMN=>true),
   
/*
     *
     *
     */
   
'age' => array(CAPTION => 'Age', SHOWCOLUMN=>true,SELECT => range(1,99) ),
   
/*
     *
     *
     */
   
'email' => array(CAPTION => 'E-mail' ),

   
EDIT_TEXT => "Edit",
   
DELETE_TEXT => "Delete",
   
EDIT_LINK => "?action=update&id=%id",
   
DELETE_LINK => "?action=delete&id=%id"
);
$crud = new crud("mysql://root@localhost/crud_test","table_1",$info);
?>
<h1>CRUD</h1>
<h2><a href='?action=new'>Add a new record</a> | <a href='?'>View</a></h2>

<?php
switch ( $_GET['action'] ) {
    case
'new':
        if (
$crud->create() ) {
            echo
" A new data was added";
        }
        break;
    case
'delete';
        if (
$crud->delete(array('id' => $_GET['id'])) == true)
            echo
"A data was deleted";
        break;
    case
'update':
        if (
$crud->update(array('id' => $_GET['id']) ) == true)
            echo
"A data was updated";
        break;
    default:
       
$crud->read();
        break;
}
?>