Dreamweaver troubles

From ShawnReevesWiki
Jump to navigationJump to search

Here I'll list some problems I've had with Dreamweaver and my solutions, when found. Keep in mind I use Mac versions.

No table found

I was working on a database-driven PHP/MySQL page. At first I could work normally, but after a certain hour I couldn't access any tables from any database in Dreamweaver CS5.

I tried several troubleshooting methods, including restarting DW, restarting the computer, deleting the preferences files, deleting the Application Support folder, deleting go-between scripts on the server, and updating the scripts to match the new addresses Network Solutions assigned my databases without telling me. That last one I thought would be it. Nope, although I think it must have been *part* of the problem. While attempting to change site settings, I got a message that the test server was not responding, so I turned on Web Sharing on my Mac, which is the assigned Test Server for my site, and that fixed the problem, probably along with the MySQL server IP address update. DW, although it shouldn't have to, uses the Test Server for all sorts of behind-the-scenes actions, so you might find this hint useful:Keep the Test Server well oiled.

This is especially relevant now that more and more Mac users are using OS versions beyond Lion. Mountain Lion does not include the Web Sharing choice in the Sharing pane of System Preferences, so it is harder to turn Apache/httpd on and off. See this document at Apple.com if your Mac's web server is off and you don't know how to turn it on: https://discussions.apple.com/docs/DOC-3083

Stale PHP/MySQL routines

The developers of PHP have decided to deprecate their original mysql library—If your php scripts use functions that begin with "mysql_" then you are using the old library; new functions and classes begin with "mysqli_". As of April 2013, Adobe's Dreamweaver handles PHP/MySQL connections and queries with the old library. CS6 does not use the improved PHP library mysqli for connections, and the routines for recordsets and dynamic texts and actions are the same as ever. See the page on PHP.net that explains the deprecation: http://docs.php.net/manual/en/intro.mysql.php

However, all the behaviors can be edited by users, since Dreamweaver uses html, javascript, and their markup language edml to tell DW how to interpret dynamic page routines. In the Dreamweaver application package folder you can find those routines and might replace PHP's mysql functions with mysqli functions, for example changing mysql_num_rows to mysqli_num_rows. You'd have to change all the functions at once, since a single connection can be only mysql or mysqli, and would require all functions to match the connection. You might think changing might be as simple as replacing all instances of mysql_ with mysqli_. However, the way mysqli returns rows may be different and some mysqli functions take different arguments, so your scripts will need more careful editing.

Oracle's mysql>mysqli converter

For a utility that promises to change mysql procedures to mysqli procedures in the most straightforward fashion, see Oracle's converter, which I chose not to use: https://wikis.oracle.com/display/mysql/Converting+to+MySQLi

It might be interesting to convert not only one's scripts but Dreamweaver's Server Behavior files themselves. Dreamweaver allows new Server Behaviors to be added, so one might add custom behaviors that use the new system. It goes deep, however, because certain behaviors like the recordset-builder require a connection themselves, and that deeper connection will have to be updated if the test-server drops mysql_ support.

I tried Oracle's converter on some Dreamweaver code and had two problems. One is that snippets must be solely the php part of scripts, not entire html pages. Another is that Dreamweaver uses a single, separate connection file with all pages that share the same connection parameters, so the connection is split from the rest of the code, and the converter doesn't handle the initial link properly anyway.

My way of converting existing web pages

I change all the functions to their mysqli equivalents, converting arguments to their proper order and place, and I add the recommended procedure mysqli_close(). Here's how I convert a typical page that lists rows of data from a database:

First change the connect-function in the connection file to this
$ConnectionName = mysqli_connect($hostname_ConnectionName,
$username_ConnectionName, $password_ConnectionName,$database_ConnectionName);
if (mysqli_connect_errno()) {
   printf("Connect failed: %s\n", mysqli_connect_error());
   exit();
}
Second, since the mysqli version of connection selects the database, you can remove the db-selecting command that appears before every query, looking like this
mysql_select_db($database_ConnectionName, $ConnectionName);
Those can be found with the following regular expression, and replaced with nothing:
mysql_select_db(\s*$\w*\s*,\s*$\w*\s*)\s*;
Third, if there's data entry, change the GetSQLValueString function to use mysqli. Specifically, noting that mysqli_real_escape_string takes the connection, not the value, as the first argument, and the value as the second argument. Also, I add this function declaration to the Connection file, removing it from all the page files, thus making them neater
 $theValue = function_exists("mysqli_real_escape_string")
? mysqli_real_escape_string($ConnectionName,$theValue) : mysql_escape_string($theValue);
Fourth, change the query call and error check to this
if(!$rsRecordsetName = mysqli_query($ConnectionName,$query_rsRecordsetName)) {die(mysql_error());}
It's pretty easy to change the from the old format by using a regular expression search and replace. Originally Dreamweaver set a query to look like this:
$resultname = mysql_query( $querystring, $connectionname) or die(mysql_error());
That can be matched by this:
(\$\w*)\s*=\s*mysql_query\((\$\w*),\s*(\$\w*)\)\s*or\s*die\(mysql_error\(\)\);
And that can be replaced with this, using regex back-references. Just go to the find dialog, select Search>Source Code and select Use regular expression, enter the above code in Find and the below code in Replace:
if(!$1 = mysqli_query($3, $2)) die(mysqli_error($3));
Fifth, note that getting a row and counting rows are pretty similar, except the row count may depend on whether the entire result is pre-loaded or buffered or not
$row_rsRecordsetName = mysqli_fetch_assoc($rsRecordsetName);
$totalRows_rsRecordsetName = mysqli_num_rows($rsRecordsetName);
Sixth, data seeks and iterating through rows is also very similar
mysqli_data
<?php } while ($rsRecordsetName = mysqli_fetch_assoc($rsRecordsetName)); ?>
Seventh, as usual, you need to free the result at the end, but you also should close the connection
mysqli_free_result($rsRecordsetName);
mysqli_close($ConnectionName);
If you know that these are the only mysql_ commands in the page file, you can replace the commands in steps 5, 6, and 7 using Find/Replace looking for mysql_ and replacing with mysqli_ .

For future web pages

When creating new web pages, I should not use the old Dreamweaver way of constructing queries, but use the more secure methods for which mysqli was improved, like using parameters and binding for passing parameters from forms into preset mysql queries.

On the other hand, I will be tempted to let Dreamweaver help me build pages the old way, then convert them using the steps outlined here.

Some interesting, simple tutorials about using mysqli, to show multiple rows of data, insert rows from form variables, and other basic routines, are available here: http://www.phpmysqlitutorials.com/category/mysqli/

Shift+I pasting on Mac

Working with Dreamweaver CS 5.5 and 6 on Mac OS X, I've noticed every time I try to type a capital I, the key-combination shift+I acts as a paste-command. I was recently adding keyboard shortcuts, and I realized I might have accidentally programmed shift+I to be a shortcut for paste. I searched for the files in Dreamweaver that contain keyboard shortcuts, and found the menus.xml file that contains the default shortcuts for all menu items. In it the key combination shift+Ins is assigned to paste, so I thought maybe Ins was being misinterpreted as its first letter, I. Lo and behold, there is a discussion about it at Adobe's forum: http://forums.adobe.com/thread/721127 There are two possible fixes. One is to delete the offending lines containing shift+Ins. Another is to use Dreamweaver's notation for controlling when to use the command, a value called "platform". Notice in the line below how the offending line was written—with platform being left empty the key combination is always applied:

<shortcut name="Paste2" key="Shift+Ins" command="if (dw.canClipPaste()) { dw.clipPaste() }" platform="" domRequired="FALSE" id="DWShortcuts_HTMLSource_Paste2" />

But since Mac doesn't have an insert key built-in, tell DW to use this command only when running on Windows:

<shortcut name="Paste2" key="Shift+Ins" command="if (dw.canClipPaste()) { dw.clipPaste() }" platform="win" domRequired="FALSE" id="DWShortcuts_HTMLSource_Paste2" />

You could use regular expressions to ensure that all lines where the key attribute has a value that includes "Ins" also has a platform attribute with a value of "win":

^(.*?key=".*?Ins".*?platform=")(\w*?)(".*?)$

Replacing the above with:

^$1win$3$

You might run into trouble if you use a line editor like awk or sed, because the XML file uses 0D, a carriage return, for line endings—Some sort of throwback to Classic Mac OS 9 Dreamweaver.

My best solution

I opened Terminal and used the following sequence of line editors to do the whole process automatically, assuming a CS 6 installation. Of course this should be done while DW is not running.

cd ~/Library/Application Support/Adobe/Dreamweaver CS6/en_US/Configuration/Menus
tr '\r' '\n'< menus.xml | sed -E 's_(.*key=".*Ins".*)(platform="")(.*)_\1platform="win"\3_' | tr '\n' '\r' > menus_fixed.xml
The above commands, explained
tr translates carriage returns "\r" to newlines "\n", reading the file as input "<".
A pipe "|" feeds the output of tr to the next command.
sed edits a single line of input at a time. The -E flag tells it to use extended regular expressions, the kind of expressions we use to identify parts of the line.
The program sed runs begins with an s, indicating that a substitution should take place. the s command is followed by a delimiter (see next item), the expression to find, that same delimiter, the output to replace the expression found, and the delimiter again.
The underscore '_' could be any character, but I chose one that looked distinct from the rest of the command so that it would be easy to find and distinguish.
The parentheses enclose parts of the expression I'd like to cut and paste into the output separately. For example, in the output, "\1" refers to the contents of the first parenthesis.
The first parenthesis includes any characters '.' of any amount '*' appearing before the characters 'key="', followed by any amount of any characters followed by 'Ins"' followed by any amount of any characters up to 'platform="' etc.
The second parenthesis includes 'platform=""'.
The third parenthesis includes anything after that up to the end of the line.
After the second underscore-delimiter '_' I wrote what I'd like to see the corrected line contain:
\1 is everything in the first parenthesis.
Then comes 'platform="win" instead of the empty version in the original file.
/3 finishes the line with everything following. The sed program ends with the single quotation mark like that with which it began.
I then pipe the result to tr again, this time translating back into the anachronistic carriage returns Dreamweaver might be expecting.
Finally, the output is saved to a file. Since the > command will overwrite anything that was there before, I use a unique name 'menus_fixed.xml'.

Then I check to see that the only differences between the original file, menus.xml, and the output, menus_fixed.xml, are the intended fixes, using the diff command:

diff menus.xml menus_fixed.xml

If the only differences are the desired differences, then I rename the old file menus.xml.bak and rename the new file menus.xml:

mv menus.xml menus.xml.bak
mv menus_fixed.xml menus.xml

Then I restart Dreamweaver and YAY! I can type capital I without freaky pasting!