Page 1 of 1

Dreamweaver vs Homemade Classes

Posted: Tue Jun 10, 2008 8:35 am
by Arocity
I recently started developing a site for my company using Dreamweaver. Of course we're using a MySQL db, so I found a really good db class to use for all my querying. Like most of these types of classes, its OO, so it's something like $db->get_var(the query) to get one value or just $db->get_results(the query) to get multiple rows and I just refer to each value in a foreach.

I've used Dreamweaver for a while but I just started dabbing in the built-in database functions. I successfully connected and started playing around and adding recordsets, but I really don't see the advantage of using it. Anybody run into problems using a DB class? Or any advantages of using Dreamweavers fancy smancy functions?

Re: Dreamweaver vs Homemade Classes

Posted: Tue Jun 10, 2008 9:51 am
by pickle
Using a database class has done nothing but good for me. It cleans up the code a bit & makes it easy to change between databases.

I've never used the Dreamweaver built-in functions so I can't definitively speak to their quality. However, I'd imagine they were built to be useful to as wide a set of people as possible, so there may be some extra functionality you don't need or some optimizations that could be done.

If you're not comfortable building your own database class, use the built-in Dreamweaver code - it's better than raw database functions.

Re: Dreamweaver vs Homemade Classes

Posted: Tue Jun 10, 2008 10:01 am
by superdezign
I haven't used DW in a long time, but last I remember, it only provided pre-written code, like a mysql_connect() and a mysql_select_db() call. I'd suggest using a database wrapper class over DW's auto-built stuff.

Re: Dreamweaver vs Homemade Classes

Posted: Tue Jun 10, 2008 11:15 am
by Arocity
I'm already currently using a database class (EzSQL for anyone interested). I just wondered if it was worth the trouble of migrating to DW's tools instead of staying with my class. One of the benefits I did see with DW is that you can get a recordset back using test data. It lets you create "filters" by setting column values to different variables(URL parameters, form vars, session vars, cookies, server values, or entered values). I attached the DW-generated code for a simple query.

Code: Select all

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
$colname_Recordset1 = "-1";
if (isset($_SERVER['em_id'])) {
  $colname_Recordset1 = $_SERVER['em_id'];
}
mysql_select_db($database_OneStop, $OneStop);
$query_Recordset1 = sprintf("SELECT * FROM employees WHERE em_id = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $OneStop) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>

Re: Dreamweaver vs Homemade Classes

Posted: Tue Jun 10, 2008 12:37 pm
by superdezign
DW's tools seem more geared towards those with little programming experience, and handles a lot of the work for you. That usually means that the flexibility of using them is limited. But if it's easier for you, then go for it.

Re: Dreamweaver vs Homemade Classes

Posted: Tue Jun 10, 2008 12:51 pm
by Arocity
Nah. It doesn't get any easier than EzSQL. [No] Pun intended.