Friday, May 8, 2009

mysql_pconnect Dreamweaver

I have recently troubleshooted a bug I have had for years. Dreamweaver by default uses mysql_pconnect when connecting to databases and this is considered bad practice for websites, (more info here ) Most servers only have a certain amount of connections and mysql_pconnect uses them all up and freezes database driven websites. The errors I would get were... Occasionally users would get a php error "Too Many Connections" when accessing a database driven page. The bug that drove me crazy for years was that my own computer would have too many connections open to the same web server and when I tried to test the PHP pages I built, they would freeze.. but it would not happen if I used another computer or tested the code on another website. And when I brought this problem to user forums, no one had a clue...
You should use mysql_connect and it is very easy to change in the connection code and does not break anything. You can simply open your connection file and change it (change mysql_pconnect to mysql_connect).

..or use this little trick I learned from the Abode support forum...

Locate the following file: C:\Program Files\Adobe\Adobe Dreamweaver CS4\configuration\Connections\PHP_MySQL\Connection_php_mysql.js. On a Mac, it should be in the same location in the Applications folder.

connParams.variables["$" + connParams.cname] = "mysql_pconnect(\"" + connParams.hostname + "\",\"" + connParams.username + "\",\"" + connParams.password + "\")";

Change it to this:

connParams.variables["$" + connParams.cname] = "mysql_connect(\"" + connParams.hostname + "\",\"" + connParams.username + "\",\"" + connParams.password + "\")";

Just to be clear the only thing that has changed is mysql_pconnect is now mysql_connect (removed the p).

In the same folder, you should find connection_includefile.edml. Open that, and change mysql_pconnect in line 12:

$@@cname@@ = mysql_pconnect($hostname_@@cname@@, $username_@@cname@@, $password_@@cname@@) or trigger_error(mysql_error(),E_USER_ERROR);

By doing the above steps, your dreamweaver will by default use mysql_connect.