☎ +34 976 234 144

Editor de Tablas

FoxPress n.º 139 · mayo de 2006 · Por la Redacción de FoxPress

Artículo publicado en la revista FoxPress en mayo de 2006. Algunos datos, versiones y funciones citados (MySQL, PHP, Visual FoxPro, Windows) pueden haber quedado desfasados.

Librería para PHP 4 & 5, no una aplicación, para permitir hacer un mantenimiento de tablas MySQL de una forma más amigable. No pretende ser una alternativa al phpMyAdmin. Sino para que los usuarios puedan hacer mantenimientos de tablas.

El código lo tienes en: http://www.phpguru.org/downloads/TableEditor/TableEditor.phps

Cualidades

Ejemplo de uso

<?php
 /**
 * Edits news table
 */
 require_once('TableEditor.php');
 
 $editor = new TableEditor($database->connection, 'comments');
 
 $editor->noDisplay('cm_parentid');
 $editor->noEdit('cm_parentid');
 
 $editor->setDisplayNames(array('cm_id'       => 'ID',
                               'cm_neid'     => 'Article',
                               'cm_datetime' => 'Date Added',
                               'cm_author'   => 'Author',
                               'cm_text'     => 'Text',
                               'cm_email'    => 'Email'));
 
 $editor->setDefaultOrderby('cm_datetime', 0);
 $editor->setConfig('searchableFields', array('cm_author', 'cm_text', 'cm_email'));
 
 $editor->setInputType('cm_neid', 'select');
 $editor->setValuesFromQuery('cm_neid', "SELECT ne_id, ne_title FROM news");
 
 $editor->addDisplayFilter('cm_text', create_function('$v', 'return str_curtail($v, 100);'));
 
 $editor->display();
 ?>

This is the demo script:

<?php
 
 /**
 * Demo of TableEditor class. Uses the following table:
 * 
 * CREATE TABLE `TableEditorDemo` ( 
 *   `te_id` int(10) unsigned NOT NULL auto_increment, 
 *   `te_name` varchar(32) NOT NULL default '', 
 *   `te_password` varchar(32) NOT NULL default '', 
 *   `te_email` varchar(32) NOT NULL default '', 
 *   `te_datetime` datetime NOT NULL default '0000-00-00 00:00:00', 
 *   `te_age` tinyint(3) unsigned NOT NULL default '0', 
 *   `te_live` enum('LIVE','NOT LIVE') default NULL, 
 *   `te_desc` mediumtext NOT NULL, 
 *   PRIMARY KEY  (`te_id`) 
 * ) TYPE=MyISAM;
 */
 
 require_once('TableEditor.php');
 
 $editor = new TableEditor($conn, 'TableEditorDemo');
     
 // $editor->setConfig('allowView', false);
 // $editor->setConfig('allowAdd', false);
 // $editor->setConfig('allowEdit', false);
 // $editor->setConfig('allowCopy', false);
 // $editor->setConfig('allowDelete', false);
 
 $editor->setConfig('perPage', 15);
 
 $editor->setDisplayNames(array('te_id'       => 'ID',
                                'te_name'     => 'Name',
                                'te_password' => 'Password',
                                'te_email'    => 'Email',
                                'te_datetime' => 'Date Added',
                                'te_age'      => 'Age',
                                'te_live'     => 'Live',
                                'te_desc'     => 'Description'));
 
 // $editor->noDisplay('te_password');
 $editor->noEdit('te_live');
 
 $editor->setInputType('te_password', 'password');
 $editor->setInputType('te_email', 'email');
 
 $editor->setSearchableFields('te_name', 'te_age', 'te_id', 'te_desc', 'te_live');
 $editor->setRequiredFields('te_name', 'te_email', 'te_datetime', 'te_age', 'te_desc');
 
 $editor->setDefaultOrderby('te_id');
 $editor->setDefaultValues(array('te_id'   => '0',
                                 'te_live' => 'NOT LIVE'));
 
 //$editor->addAdditionCallback(create_function('$data', 'foreach($data as $k => $v) {$body[] = "$k => $v";} mail("joe@example.com", "Row added", implode("\n", $body));'));
 //$editor->addEditCallback(create_function('$data', 'foreach($data as $k => $v) {$body[] = "$k => $v";} mail("joe@example.com", "Row edited", implode("\n", $body));'));
 //$editor->addCopyCallback(create_function('$data', 'foreach($data as $k => $v) {$body[] = "$k => $v";} mail("joe@example.com", "Row copied", implode("\n", $body));'));
 //$editor->addDeleteCallback(create_function('$data', 'foreach($data as $k => $v) {$body[] = "$k => $v";} mail("joe@example.com", "Row deleted", implode("\n", $body));'));
 
 function validateAge(&$obj, $data)
 {
     $data = (int)$data;
 
     if ($data < 18 OR $data > 80) {
         $obj->addError('Invalid age! Please enter an age between 18 and 80');
     }
 
     return $data;
 }
 
 $editor->addValidationCallback('te_age', 'validateAge');
 
 $editor->addDisplayFilter('te_desc', create_function('$v', 'return substr($v, 0, 100) . "...";'));
 
 $editor->display();
 
 ?>

Comparación con otras herramientas similares

Opciones MySQL TableEditor phpMyEdit dbPerceptor
Tipo Library Library Application
Licencia GPL GPL GPL
PHP Version 4.3+ 4.1.2+ 4
Instalación Coding Required Utility Provided Configuration Required
URL Link Link Link
Add Record ✔ Sí ✔ Sí ✔ Sí
Edit Record ✔ Sí ✔ Sí ✔ Sí
Copy Record ✔ Sí ✔ Sí ✘ No
View Record ✔ Sí ✔ Sí ✔ Sí
Delete Record ✔ Sí ✔ Sí ✔ Sí
MultiplesDeletes de golpe ✔ Sí ✘ No ✔ Sí
Search ✔ Sí ✔ Sí ✘ No
Advanced Search ✔ Sí ✘ No ✘ No
CSV Download ✔ Sí Commercial Extension ✘ No
Activar/Desactivar las funciones anteriores ✔ Sí ✔ Sí ✔ Sí
File Upload ✘ No With patch & callbacks ✔ Sí
Custom Callbacks Supported Pre-Display (per column), Data Filter, Post Add/Edit/Copy/Delete Pre/Post actions via include files ✘ No
Record Paging ✔ Sí ✔ Sí ✔ Sí
Ordenación de registros ✔ Sí ✔ Sí ✔ Sí
Ordenación múltiple ✘ No ✔ Sí ✔ Sí
Filtrado de registros ✔ Sí ✔ Sí ✘ No
Required Fields (Add/Edit) ✔ Sí ✔ Sí ✔ Sí
Custom Field Types (Add/Edit) Date/Time/Datetime, Email, Password, Bitmask Password, Calendar and Richtext HTML editing via extensions Spellcheck, Rich Text, Word Count, Calendar
Field/Column Hiding ✔ Sí ✔ Sí ✔ Sí
Múltiples estilos de navegación ✘ No ✔ Sí ✘ No
Look/Feel Manipulation ✔ Sí ✔ Sí ✔ Sí
Soporte multilenguaje ✘ No ✔ Sí ✘ No
Logging User Actions Any via Custom Callback Function MySQL Table and Email ✘ No
Foreign Key Support (ie. 1:M) ✔ Sí ✔ Sí ✔ Sí
Soporte de Join de Tablas ✔ Sí ✔ Sí ✘ No

Listado de la tabla de pruebas con la librería MySQL TableEditor, con botones Search, View, CSV, Add, Edit, Copy y Delete

¿Quieres llevar la IA a los datos de tu empresa?

En una auditoría gratuita de 30 minutos vemos qué caso concreto te ahorraría más trabajo.

Reservar mi auditoría →