MySQL Management in Flex

Source: Internet
Author: User
Tags command line dsn getmessage mysql pear php script web services

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

%

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.