Dreamweaver has included server programming and database server programming features for over 10 years. The server behaviors in CS5 are virtually unchanged from CS4. The basic concept is that Dreamweaver inserts code snippets into your webpages that perform basic server-based functions based on the familiar panel-based interface used for designing web pages.
In lesson 6, David Powers gives us a great tour of the various PHP/MySQL server behaviors built into Dreamweaver CS5. But he also discusses the various drawbacks to using the built in server behaviors (see page 208) and the textbook explores alternative approaches to server programming in subsequent chapters starting with the next lesson.
While server behaviors are generally an imperfect option for production systems, they are very useful for us in this class, because they are an easy way to demonstrate how PHP and MySQL work together to perform basic database functions. We will explore Lesson 6 in two parts, the first part of the chapter creates a working user login web system. In the second part of the chapter, in a later post, we will explore the server behaviors that create, update, read and delete database records.
Getting access to MySQL from within Dreamweaver is very simple. Open the Databases panel (Menu Window->Database) and click the plus sign. Complete the form and click save. This will create a database object in the Databases panel, where you can inspect the structure of the tables and columns. It will also create a Connections folder with a php file that contains all of your connection information, including your SQL password in plain text. This cannot be seen by any browser – php is never visible from the webserver, as you know, so that the file is secure once it is uploaded. Keep in mind that databases usually store very sensitive information so keep these files in place where it can’t be seen by anyone who shouldn’t have access to the database.
The Insert Record Server Behavior
The tutorial on pages 177-183 is pretty straightforward. Don’t miss the tips, notes and sidebars, they have great information that is useful for more than just server behaviors. Note the blue highlight indicating that the form is ‘programmed’. Using this server behavior is so simple and yet it creates over 50 lines of complex, almost indecipherable code. Notice where the server behavior created code and where the SQL insert statement is. Notice also how the Insert Record server behavior code is implemented as a self-processing form (see page 191). The webpage itself has states implemented in PHP conditionals that change from pre-submit to submit to post-submit.
The Log In User, Restrict Access to Page & Log Out User Server Behaviors
The user authentication behaviors work together to build a sophisticated website login system with PHP & MySQL in a snap. Follow the tutorial on pages 183-192 and you will have the fundamentals for building a secure web application login system. With just a few Dreamweaver object definitions and a few lines of code (PHP handles text encryption with one function – sha1() – the Secure Hash Algorithm ) you have a production system!