Part 1: Server Behaviors in Dreamweaver CS5 with PHP / MySQL

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.

Dreamweaver SQL Connection windowCreating a MySQL Connection File

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.  Dreamweaver Database PanelThis 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

dreamweaver dynamic database formThe 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!

8 comments for “Part 1: Server Behaviors in Dreamweaver CS5 with PHP / MySQL

  1. Leeana
    March 3, 2011 at 10:11 pm

    Hi Jay,

    At home and can’t get MySQL table to show up in dreamweaver. Is the problem with the JC server?

    Thanks Leeana

  2. Mark Alarie
    March 8, 2011 at 7:29 am

    As I work my way through Lesson 6, so far I have been able to make the pages work except on pages 190-191 encrypting passwords.

    If I take my working log-in page and insert the recommended encryption code and test the page, it shows up as a blank page in the browser. I tried and checked the code a couple times on both my log-in and add-users pages with the same results. If I remove the encryption code, they work.

    Anyone else have similar results?


    • March 8, 2011 at 7:50 am

      Mark – Any PHP syntax error will cause that behavior. I didn’t have that problem. Check those few lines carefully to make sure everything is typed correctly. Try running a page with just that code isolated to echo the encrypted string.

  3. Tomas
    March 9, 2011 at 4:22 pm

    Mark – have you created a new user after you added the encryption code?

  4. Mark Alarie
    March 14, 2011 at 7:11 am

    I believe my problem with the encryption code on page 191 in the book is that sha1 looks like shal when typing in the code.
    Note it should end with number ’1′ not letter ‘l’.


  5. June 18, 2011 at 8:22 am

    My Name is Chinedu! Actually am a new person in using dreamweaver to build a website, i use frontpage very well but i want to upgrade. Am having problem using server behavior panel in dreamweaver when ever i click on the server panel, the plus link will not be highlighted and the window will display ‘before you can user template you have to create site for this page, choose a document type’. Please if any body knows solution for this please send me reply at or thanks

    • June 20, 2011 at 1:25 pm

      @Chinedu You need to have a Dreamweaver site definition with a server programming model defined before using Server Behaviors.

Comments are closed.