Flex中的MySQL管理(1)
学习使用RIA Framework Flex创建MySQL管理UI PHPMyAdmin的出现震撼了业界,这毫无疑问。它当然是基于PHP的最佳应用程序,因为它将MySQL管理界面由命令行的形式改为了web浏览器的形式。不过,虽然它的功能很强大,但使用并不太方便,界面也不够美观。因此,我
学习使用RIA Framework Flex创建MySQL管理UI
PHPMyAdmin的出现震撼了业界,这毫无疑问。它当然是基于PHP的最佳应用程序,因为它将MySQL管理界面由命令行的形式改为了web浏览器的形式。不过,虽然它的功能很强大,但使用并不太方便,界面也不够美观。因此,我尝试通过Rich Internet Application框架设计更理想的MySQL前台管理程序。
要达成此目标本可选用Ajax。但我不想处理客户端的不兼容问题。当然,Silverlight也是不错的选择,但它仍不够成熟。 之所以选择Adobe Flex,是因为它拥有富用户接口工具集和方便的web服务集成功能,而且它生成的Flash应用程序能够以相同方式在任何操作系统中运行。
我学习了很多有关创建应用程序方面的知识:如何为PHP程序创建安全的SQL web服务;如何通过Flex访问web服务;如何将web服务返回的数据输入数据网格中并显示。在本文中,我将引领读者从前台到后台,逐步创建MySQL管理程序。读者从中可了解一些有用的信息,以创建自己的Rich Internet应用程序。
创建后台程序
Flex应用程序擅长与web服务通讯,以发出请求及提交数据。因此,首先需要创建一个非常简单的PHP脚本,它将以XML格式返回数据库列表、表或表中的数据。
清单1:req.php
<p><?php <br>require_once("MDB2.php");<br>$sql = 'SHOW DATABASES';<br>if ( $_REQUEST['mode'] == 'getTables' )<br>$sql = 'SHOW TABLES';<br>if ( $_REQUEST['mode'] == 'getData' )<br>$sql = 'SELECT * FROM '.$_REQUEST['table'];<br>$dsn = 'mysql://root@localhost/'.$_REQUEST['db'];<br>$mdb2 =& MDB2::factory($dsn);<br>if (PEAR::isError($mdb2)) { die($mdb2->getMessage()); }<br>$dom = new DomDocument();<br>$dom->formatOutput = true;<br>$root = $dom->createElement( "records" );<br>$dom->appendChild( $root );<br>$res =& $mdb2->query( $sql );<br>if (PEAR::isError($mdb2)) { die($mdb2->getMessage()); }<br>while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC))<br>{<br>$rec = $dom->createElement( "record" );<br>$root->appendChild( $rec );<br>foreach( array_keys( $row ) as $key ) {<br>$key_elem = $dom->createElement( $key );<br>$rec->appendChild( $key_elem );<br>$key_elem->appendChild( $dom->createTextNode( $row[$key] ) );<br>}<br>}<br>$res->free();<br>$mdb2->disconnect();<br>header( "Content-type: text/xml" );<br>echo $dom->saveXML();<br>?></p> Copy after login |
该脚本的第一项工作就是利用MDB2库连接数据库。如果没有安装MDB2库,则可使用PEAR安装该库,如下所示:
% pear install MDB2<br>% Copy after login |
如果PEAR无法正常运行,可访问http://pear.php.net/mdb2,然后下载源代码并将其解包到PHP的include路径下。MDB2是通用的数据库适配器层,它已取代了广为使用的PEAR DB库。
脚本的第二项工作就是创建XML DOM Document对象,该对象将用来创建要输出的XML树。从此处开始,它将运行查询,并在XML树中添加row和column作为XML标签。最后,该脚本将关闭所有连接,并将XML保存到PHP输出流中。
选用XML DOM对象的原因是,它可避免任何与数据、不对称标签等有关的编码问题以及各种可能使XML产生混乱的因素。我可以将调试XML数据流的时间节省下来做其他许多更有意义的工作。您一定也会这样做。
将该脚本安装到本地机器上的可运行目录下,然后使用curl命令向服务器发出请求。
% curl "http://localhost/sql/req.php"<br><?xml version="1.0"?><br><records><br><record><br><database>addresses</database><br></record><br><record><br><database>ajaxdb</database><br></record><br>...<br>% </records> Copy after login |
在本例中,我并未指定数据库或模式,这会要求脚本返回可用数据库的清单。假如web服务脚本有权执行该任务,则在curl语句后面就会显示执行的结果。在本例中,将以标签的形式显示不同数据库的列表。
该脚本返回的所有数据都带有
除了使用curl命令,还可将URL输入浏览器中,然后在加载页面后选择“View Source(查看源文件)”。
在下例中,将连接articles数据库并获取它的表格列表。结果如下:
% curl ".../req.php?mode=getTables&db=articles"<br><?xml version="1.0"?><br><records><br><record><br><tables_in_articles>article</tables_in_articles><br></record><br></records><br>% Copy after login |
articles数据库中只有一个名为article的表格,这并不奇怪。要运行经典的select * from article查询以获取所有记录,可使用以下URL:
<p>% curl ".../req.php?mode=getData&db=articles&table=article"<br><?xml version="1.0"?><br><records><br><record><br><id>1</id><br><title>Apple releases iPhone</title> <br><content>Apple Computer is going to release the iPhone...</content><br></record><br><record><br><id>2</id><br><title>Google release Gears</title> <br><content>Google, Inc. of Mountain View California has...</content><br></record><br></records><br>%</p> Copy after login |
表格中有两条记录:第一条显示Apple公司将发布超炫的IPhone;第二条显示Google公司将发布同样很炫、但用途完全不同的Gears系统。
在本地机器上安装了极为强大且灵活的后台程序后,就可以着手为其创建Flex前台程序了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.
