Instant PHP 4
May 17, 2002
|
Use PHP 4 to create calendars, shopping carts, WAP pages and much
more using this practical cookbook-style guide. Packed with
ready-to-use applications and organized by application type, this
is an ideal resource for when you need quick and easy access to
hands-on information.
|
Web-Based Database Administration
IN THIS CHAPTER:
chapter5_common.php—Common set of functions used for connecting to the database and displaying HTML output used throughout the chapter
chapter5_dbAdmin.php—Class with methods for administering a table and submenu to perform database administrative actions
chapter5_dbMonitor.php—Class with methods for monitoring the status of the database and submenu to perform database monitoring actions
chapter5_login.php—Script to handle login/logout of the application
chapter5_mainMenu.php—Presents the main menu of options and verifies that the user is able to log in to the database
chapter5_sql.php—Class with methods to execute SQL queries and report results
chapter5_tableAdmin.php—Class with methods to administer database tables and submenu to perform table administrative actions
chapter5_userAdmin.php—Class with methods to administer users and submenu to perform user administrative actions
The project for this chapter is to develop a web-based database administration application. The code in this chapter is designed to allow a user to administer a MySQL database. When possible, however, the code has been segmented to allow it to be easily adapted to the other databases supported with PHP.
The chapter includes code for many of the basic database operations such as listing databases and their corresponding tables, along with overall database status. It also includes a query interface for running queries on demand that don't fall within the predefined administration options.
Application Requirements
The general requirement for this application is to allow a user to easily administer a MySQL database from a web browser. This would allow a user to work with the database from remote locations, regardless of whether they have a MySQL client installed on their machine. The core requirement of the application is to allow users to connect to the database through a web browser. Once connected, the operations a user can perform can be grouped into the following categories: database administration, table administration, database monitoring, user administration, and SQL query execution.
The application described by these requirements does not cover all possible administrative tasks, but meets many of the common needs for a user who wants to have control over their database regardless of what machine and location they are currently working from.
Connection Requirements
The connection is established by prompting the user for their username, password, and the hostname that the user is authorized to access the MySQL server from. Due to the stateless nature of the Internet, an open connection cannot be maintained between the browser and the database; therefore, once the user has connected successfully, the application keeps track of who the user is and which database within the MySQL server they are currently working with.
Database Administration Requirements
The next requirement of the application is to allow the user to perform overall database administration duties. The first duty is to provide a listing of which databases are available on the server that the user may access. Second, a user may select which database they would like to work with for subsequent requests that access a specific database, such as table administration or SQL queries. Finally, the user is allowed to create and drop databases as long as their user permissions allow such actions.
Table Administration Requirements
Similar requirements are necessary for table administration. The user can list all of the tables available within a selected database, as well as view a description of the columns that make up a particular table. In addition to these requirements, a user may create and drop a table from a database. Finally, the user can display contents of a table.
Server Monitoring Requirements
The database monitoring requirements are designed to allow the user to view the overall status of the MySQL server. A user may view the server status, the version of the MySQL software, and its current variable settings. Finally, a listing of the server processes are available for the user to examine.
User Administration Requirements
In the case of user administration, the application provides a listing of all users who are allowed to log in to the database. Second, the facility to add and remove users is available. Finally, the ability to alter a user's information or to log in to the server as an entirely different user is possible.
SQL Execution
The last requirement of the application is to let users execute raw SQL queries. This provides a mechanism for the user to do other administrative functions that are not part of the point-and-click requirements of the application. With the inclusion of a query interface, the functionality of the application is greatly expanded to include almost all of the actions that a user could perform if they had a direct client connection to the MySQL database.
Instant PHP 4
Application Design
|