|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Dreamweaver PHAkt
The InterAKT Dreamweaver MX PHP server model
By: Alexandru Costin
Mar. 2, 2004 12:00 AM
Originally, I was going to use this article to present a tutorial on using PHAkt in conjunction with PostgreSQL to create dynamic Web sites. However, as I've just returned from MAX 2003 (a nice show, really), my vision changed a bit. I was repeatedly told, "Dreamweaver users don't work with server behaviors - they prefer to code manually." I decided to shift the focus of this article to include a clearer view of server behaviors as well as the PHAkt product overview. Introduction That's how PHAkt - the PHP Server Model for Dreamweaver - was born. It was the most complex effort of its kind, and it was released as an open source product (free for download) to a huge market success. PHAkt History PHAkt was very popular in the Ultradev 4 era - people downloaded it more than 200.000 times, and we received raves across the board from the Dreamweaver community. But starting with the MX version, Dreamweaver began supporting PHP in the PHP_MySQL server model instead. "Why would one still need PHAkt?" you might wonder. The answer is simple: PHP_MySQL (as its name implies) can connect only to the MySQL database server. While a large number of Web developers will live with this, some will opt not to use Dreamweaver for PHP development because of its inability to use other databases. Despite its extreme speed, MySQL is still a "toy" database, with no support for triggers, stored procedures, or referential integrity. Even if you use MySQL, PHAkt can still help you create powerful applications. With a PHAkt site, you will be able to switch to another database later without regenerating all your pages - something impossible with PHP_MySQL. Web Development with Dreamweaver Multiple scripting languages may be used to create dynamic Web sites; you might be familiar with some of them: ASP (Microsoft Active Server Pages), CFM (Macromedia ColdFusion), and JSP (JavaServer Pages). One of the newcomers in this area is PHP (PHP: Hypertext Preprocessor). To create such Web sites, developers need to create pages that connect to a database and then write the actual HTML output to the client browser (see Image I). To write script pages, you can use a text editor or you can choose to use a professional tool to leverage your work. Of course, the leader of this latter market is Dreamweaver MX, the best Web IDE. Despite popular belief, Dreamweaver MX is not only a designer tool, but also a dynamic Web programmer tool. Starting with the fact that 90% of dynamic Web development consists of creating lists with database information and creating forms to update the database, Dreamweaver provides a suite of "server behaviors" to automate those tasks. This is one of the most important features in Dreamweaver MX, and is often not used to its full potential (read "at all"). Server behaviors are reusable code blocks you can use in your Web sites. Aside from the code, they come with a useful GUI that allows you to set various parameters to the code block. Let's look at one of the most used server behaviors (SBs), the recordset. Its role is to connect to a database, perform a SQL query, and return a recordset (a data structure that will store all the rows and fields returned from the database). As you can see in Image II, we can set the name and the database connection to be used. Notice that most of the SB interface parameters are bounded properties, meaning that they are dynamically retrieved from the database server without the developer having to memorize or type them. After you select a database (the database dropdown is loaded with the available database connections), the table menu is updated with all the tables in the current database, and so on. Applying this SB on the page will output the following code: <?php What makes SBs useful is that they not only generate the code for you, but they also recognize it on the page and allow you to update one code block by loading the configuration interface with all the parameters correctly set. This allows you to change them and reapply the SB. If we go behind the scenes, there is a very complex regular expression engine that stands behind this mechanism, and there are also some limitations in recognizing the already-applied code blocks, but you can easily adapt to them. Even if some programmers choose not to use SBs ("they restrict my options," "I don't like the generated code," etc.), you should understand that used wisely, they can really improve how you create Web sites. Picture two situations where you want to create a dynamic Web site:
Enough about SBs. I encourage you to look closely at what they can do for you, as you will be amazed. If you want to find more, Dreamweaver has tons of documentation on them and you will find everything you want in there. Configuring Your Site for PHAkt You will need access to a computer with Apache, PHP, and a database installed (the database will probably be MySQL, but any database will do). You will find a lot of information about installing PHP and preparing a workstation for serving dynamic pages at www.dreamweavermxsupport.com. If you want to test PHAkt at work with another database server, you can get PostgreSQL and install it. PostgreSQL is one of the most advanced open source database servers available, and can compete seriously with any major player in the industry. Multiple ports for Windows are available; we've found UltraSQL to be the easiest to install (http://techdocs.postgresql.org/guides/Windows). Once your Apache/PHP server is set up, configure Dreamweaver to edit PHP files using PHAkt. The first step in starting to use PHAkt is to set up the Dreamweaver site (I assume you are already familiar with this, so I won't elaborate) As shown in Image III, instead of PHP_MySQL, you have to select PHP_ADODB for the Testing Server of your configured site. PHP_ADODB is the server-model name for PHAkt: a confusing naming convention we set up a long time ago, but we have to live with it to keep the backwards compatibility. When you create new .php files in this type of Dreamweaver site, they will be "stamped" with a small PHP comment in their upper section: <?php //PHP ADODB document - made with PHAkt 2.6.2?> This is our way of recognizing a page as a PHAkt page, so you should leave this comment as is. It will not affect your site performance, nor will it be included in your site HTML output. Improved Database Connection Our ADOdb (actually it's not ours, it's an open source library written by John Lim - http://php.weblogs.com - but we have improved it a little bit) simply consists of some PHP files that will dynamically choose the correct native database connection library from PHP and use it. When installing a PHAkt site, you will not have to install anything on your PHP server; just copy the site's files and ADOdb will be automatically copied, too. Let's illustrate the difference between ADOdb and pure PHP code by comparing the native PHP_MySQL code with PHAkt code for a simple SQL query. The PHP_MySQL code looks like: mysql_select_db($database_mysql_demo,
$mysql_demo); You can see the mysql_* API calls, and it's pretty clear that this code is database specific. The PHAkt code looks much cleaner, as the SelectLimit() method called is not database specific: $query_Recordset1 = "SELECT * FROM
name_nam"; Of course, ADOdb will call the mysql_query function, but it uses encapsulation to hide this implementation detail for you. Creating the Database Connection When you click on the + sign, Image IV appears. As you can see, the configuration screen is much more complex than the regular PHP_MySQL database configuration interface. This initial complexity is in fact the window to many useful and available features. Apart from selecting the database type, you can define a format for the DATE fields in the database and a location for the application messages to be used later in the application. You can also decide whether or not the database connection is persistent (persistent connections use a pool of connections to the database layer to avoid the reconnection time penalty, and thus are slightly faster but more resource intensive). Supported Databases We have used PHAkt mostly with MySQL, PostgreSQL, MsSQL, and Access. We've heard various success stories from our clients who use Oracle, Informix, and Firebird (see Image V). Once you create the connection, you can start using PHAkt to create Web sites. As we have followed the Macromedia GUI's "unwritten" design rules (believe me, they are *very* strict when it comes to uploading on the Exchange), our interfaces look very similar to the PHP_MySQL ones for all of the server behaviors provided. Other Improvements Date Locales French clients want to edit dates like "m-d-Y", Americans want "Y-m-d", and Germans want "d.m.Y". Because they used MySQL (where you don't have any real way of setting the date locales on the server) on hosted environments (where we can't access the server to change the server locale or anything), we were forced to think of a solution that would allow us to read and write dates in a specific format in the database. Server Formats from Dreamweaver is a solution when displaying dates, but it can't handle updates at all. Our solution was to change the ADOdb wrapper and the PHAkt underlying libraries to allow us to set the date locale for a specific connection, and then use this locale transparently when displaying dates and when inserting/updating records in a table. Thus, it's very straightforward for any developer to create internationalized applications (from the date's point of view, at least). The date-locale support was thoroughly tested with MySQL, PostgreSQL, and MsSQL, but we will continue its implementation based on a client request. Supplemental Server Behaviors When working with PHAkt, you will be able to use:
Extending PHAkt Only a few companies create extensions for PHAkt (they usually focus on PHP_MySQL), but you will find all you need in the list below (shopping cart extensions, query builders, form generators, horizontal looper and nested repeat regions, etc.):
PHP in the Enterprise To get some real information on the PHP market, we conducted extensive market research, and the results may be helpful if you are really serious about PHP. Our research involved 700 respondents, and we managed to get a clearer view on the software development market for PHP and its relationship to medium and large enterprises. Read the survey to see our estimate of the number of PHP developers, the average price of a PHP Web site, and some golden rules to promote PHP in an enterprise setting. Our full market research analysis is located at www.interaktonline.com/index_art_11.html. Conclusion Upside Overall, PHAkt is a step further along in creating PHP sites with Dreamweaver MX, as it integrates a set of improvements that ease software development. Downside Also, because of the ADOdb usage, PHAkt is slightly slower than native connections, but if you want to create something extensible you will find ways to correct this using various techniques (PHP accelerators, indexes in the database, ete.). PHAkt's Future We plan to merge PHAkt with the InterAKT Transaction Engine (tNG), a much better way of creating forms with associated events (send mail, upload image, et.). We want to include PHP 5 support and enlarge the included server behaviors and commands set. Next Steps You will find server behaviors to create lists with records from a Table - Repeat Region, to apply conditional regions - Show if Recordset is Empty, and to create insert, update, and delete forms for a table. PHAkt also comes with several tutorials and documentation, so you should be able to get started quickly. I hope you have a better view of what Dreamweaver MX, server behaviors, and PHAkt can do for you. Just go and download our extension and start creating dynamic Web sites now! Resources www.interaktonline.com/products/PHAkt/ www.interakt.ro/products/bbs/index_0.html http://php.weblogs.com/ADOdb/ Reader Feedback: Page 1 of 1
Your Feedback
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||