Learn to use RIA Framework Flex to create a MySQL admin UI
phpMyAdmin's appearance shook the industry, no doubt. It is, of course, the best PHP application because it changes the MySQL admin interface from the command line to the form of a Web browser. However, although its function is very powerful, but the use is not very convenient, the interface is not beautiful enough. Therefore, I am trying to design a more ideal MySQL foreground management program through the rich Internet application framework.
You can use Ajax to achieve this goal. But I don't want to deal with client incompatibility issues. Of course, Silverlight is a good choice, but it's still not mature enough. Adobe Flex is chosen because it has a rich user interface toolset and convenient Web service integration capabilities, and the flash applications it generates can run in any operating system in the same way.
I've learned a lot about creating applications: How to create a secure SQL Web service for PHP programs, how to access a Web service through Flex, how to enter the data returned by a Web service into a data grid, and display it. In this article, I will lead readers from the foreground to the background, and gradually create the MySQL management program. Readers can learn some useful information to create their own rich Internet applications.
Create a background program
Flex applications are good at communicating with Web services to send requests and submit data. So, first you need to create a very simple PHP script that returns data from a database list, table, or table in XML format.
Listing 1. req.php
<?php
Require_once ("mdb2.php");
$sql = ' show DATABASES ';
if ($_request[' mode '] = = ' Gettables ')
$sql = ' show TABLES ';
if ($_request[' mode '] = = ' GetData ')
$sql = ' SELECT * from '. $_request[' table '];
$dsn = ' mysql://root@localhost/'. $_request[' db '];
$mdb 2 =& mdb2::factory ($DSN);
if (Pear::iserror ($mdb 2)) {Die ($mdb 2->getmessage ());}
$dom = new DOMDocument ();
$dom->formatoutput = true;
$root = $dom->createelement ("records");
$dom->appendchild ($root);
$res =& $mdb 2->query ($sql);
if (Pear::iserror ($mdb 2)) {Die ($mdb 2->getmessage ());}
while ($row = $res->fetchrow (MDB2_FETCHMODE_ASSOC))
{
$rec = $dom->createelement ("Record");
$root->appendchild ($REC);
foreach (Array_keys ($row) as $key) {
$key _elem = $dom->createelement ($key);
$rec->appendchild ($key _elem);
$key _elem->appendchild ($dom->createtextnode ($row [$key]));
}
}
$res->free ();
$mdb 2->disconnect ();
Header ("Content-type:text/xml");
echo $dom->savexml ();
?>
The first task of the script is to use the MDB2 library to connect to the database. If the MDB2 library is not installed, you can use pear to install the library, as follows:
% Pear Install MDB2
%