This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature: Web Development

Create a Web-based interface for MySQL databases in a flash with phpMyEdit

By Dmitri Popov on March 08, 2007 (8:00:00 AM)

Share    Print    Comments   

If you've ever worked with MySQL databases, you are probably familiar with phpMyAdmin, a PHP-based tool that allows you to create and manage MySQL databases via a browser. It is an indispensable tool for anyone building a PHP/MySQL-based Web application. But while phpMyAdmin eases the task of creating and managing the back end of your Web application, it is of no help when it comes to designing a Web-based interface. To simplify creating PHP-based front ends, try phpMyEdit, an ingenious piece of software that can generate a functional Web interface in a matter of minutes -- no PHP programming skills required. Although phpMyEdit hides the complexity of generating a PHP-based interface, it still offers an easy-to-use yet powerful mechanism to customize virtually any aspect of the created front end.

Let's start with creating a simple front end to an even simpler MySQL database, consisting of a single table and three fields: ID, Notes, and Source. Download the latest release of phpMyEdit, unpack it, and move the resulting folder into the document root of your Web server. Point your browser to http://serveraddress/path/to/phpMyEdit/phpMyEditSetup.php. If phpMyEdit works properly, you should see a database connection form. Fill out the required fields and press the Submit button. phpMyEdit then displays a list of the fields in the specified database table, and you have to select a so-called identifier (a primary key in MySQL terminology). phpMyEdit then asks you to provide the name and title you want to use for the generated page. Here you can also decide whether the page should have a header/footer and use a basic CSS stylesheet by ticking the appropriate check boxes. Once you've pressed Submit, phpMyEdit generates the page and writes it to the phpMyEdit folder. It also conveniently displays the generated code, which you can copy and paste into a text editor for additional tweaking.

Now point your browser to the created page, and you should have a basic front end to your MySQL database. Using it, you can create, modify, delete, view, sort, and filter records. While the default interface is functional as it is, phpMyEdit offers settings you can tweak to make the interface better suit your needs. You can find detailed instructions for all these tasks in the program's documentation.

Let's start with something simple, like changing the number of records per page. To do this, open the generated .php file in a text editor, locate the $opts['inc'] = 15; line, and replace the default value with the number you want. If you want to display all the records in the table on one page, set the option to -1.

Another thing you might want to change is user permissions. By default, anyone can access and modify the data in the database. If you want to give visitors read-only access, you can do that by modifying the $opts['options'] option. Permissions here are specified by using or omitting appropriate letters. For example, if you want to disallow users to modify and delete records in the table, all you have to do is to remove the C and D letters from the default ACPVDF string, so the option looks like this:

  $opts['options'] = 'APVF';

By default, the created page sorts records by their identifier, but you can also change that by modifying the $opts['sort_field'] option. For example, if you want to sort records by the Notes field, the option will look like this

  $opts['sort_field'] = array('Notes');

You can also specify more advanced sorting based on several fields. The following sorting settings sort records by both Notes and Source fields:

  $opts[sort_field] = array(Notes, Source);

Since phpMyEdit supports SQL, you can use it to manipulate the data using SQL queries. Let's say you have a bibliography database, where the author's name is stored in two separate fields: Firstname and Lastname. Using a simple SQL statement you can create a new Author field that concatenates the data from the Firstname and Lastname fields:

  $opts[fdd][Author][sql] = CONCAT(Firstname, , , Lastname);

The appearance of the front end is controlled by a simple CSS stylesheet, and you can tweak it to your heart's content to achieve the results you want. You can also modify the overall look of the interface another way without fiddling with CSS: phpMyEdit allows you to customize the navigation buttons using the $opts[navigation] option. This option defines where on the page the navigation buttons appear (U -- above the table, D -- below the table) and the button type to use (B -- default buttons, T -- text links, G -- graphics links). Using these parameters, you can specify the appearance of the navigation buttons. The following settings display the graphics buttons below the table:

  $opts[navigation] = DG;

These are just a few simple examples of what you can do with phpMyEdit, and there is much more to it. phpMyEdit also supports such advanced features such as triggers, CGI variables, JavaScript functions, and extensions.

Dmitri Popov is a freelance writer whose articles have appeared in Russian, US, British, German, and Danish computer magazines.

Dmitri Popov is a freelance writer whose articles have appeared in Russian, British, US, German, and Danish computer magazines.

Share    Print    Comments   

Comments

on Create a Web-based interface for MySQL databases in a flash with phpMyEdit

Note: Comments are owned by the poster. We are not responsible for their content.

Re:Better think twice

Posted by: Anonymous Coward on March 10, 2007 03:33 AM
Grzegorz,

It's GNU, so why don't you rewrite and re-factor it yourself and contribute it back, either to myPhpEdit or by creating a new project, instead of complaining about it?

#

Re:Better think twice

Posted by: Administrator on March 10, 2007 08:11 PM
I'm not really complaining. As I said, if you're happy with what the program offers by default, you can do a lot with it. I used it to implement a workstation management system for a number of largish LANs (c. 500-700 hosts each), by setting up a separate script for each table, with links between them, and navigation sprinkled on top of the "index.php" files - complete with log browser, user and admin management etc. I was really impressed with the speed and ease of the initial setup. However, as more modifications were required, things got worse. In some cases I was able to set up new config variables in the $opts array in the index.php files, identify appropriate methods in the class file and modify them to implement new behaviour. But in other cases I needed to modify the internal workings of the class file and it turned out to be a painful experience. Really, the three recursive passes are an unnecessary annoyance, contributing a lot to the code's illegibility. And let me repeat - you don't do OOP by cramming all logic into one monster class that gets new methods and properties each time you add a feature. I'd be so much happier to see good old imperative programming with a well defined function library in an include file.

Also, it's not that I didn't try - after setting up the system I spent some time investigating the possibility of re-writing/refactoring the main class file, it just turned out to be a major undertaking. Try it. Take the 3200+ lines long class definition, read it, understand it well enough to be able to keep basically the same data flow, then design a new class system to implement the same behavior with, say, templating (and thus caching and other goodies) in mind. Eventually, I just got assigned to other tasks, a colleague took over the system and instead of modifying it, wrote his own from scratch.

I don't mean to bash or whine. It may work excellent for you, it's feature-rich and admin-friendly. It's just that if the program deserves to be presented to potential users on linux.com, potential users also deserve to be informed about its deficits, not just good sides. "You can always make it better" is not an excuse for making it bad.

#

Dataface

Posted by: Anonymous Coward on May 11, 2007 09:26 PM
Have a look at <a href="http://fas.sfu.ca/dataface/" title="fas.sfu.ca"> Dataface</a fas.sfu.ca>. Works as easily as described above, but the code is well maintained, it uses templating and it is more flexible I think.

#

I've used it

Posted by: Administrator on March 09, 2007 04:52 AM
and it is a great piece of software.

#

Better think twice

Posted by: Administrator on March 09, 2007 06:48 PM
If you're absolutely positive the built-in (indeed impressive) feature set of the script is everything you'll want to use, just go ahead. You can build quite complex database interfaces by using separate installations of the program for separate tables, each with external references to others. But if you assume the possibility of extending it, or tinkering with it in any way, think twice. The code is a mess. No MVC, not even a template system. HTML is spat out by a miscellany of methods, glued together by other multple methods, making it very hard to change anything non-trivial under the hood. The authors' bizarre dedication to using just one source file led them to using it recursively in as many as three passes, when using three (or more) separate files would be so much cleaner. And I'm by no means a programming guru, but I don't think using just one monster class with over 100 methods and tens of properties is what the creators of object-oriented programming meant it to be. The program should've been rewritten and re-factored long ago.

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya