Forums
This topic is locked
DW Default Code Question
Posted 20 Apr 2005 18:06:51
1
has voted
20 Apr 2005 18:06:51 Matt Bailey posted:
I'm just curious to know what the block of code below (that DW creates when you use the INSERT or UPDATE record server behaviours) is for and whether it's ok to delete it? None of the PHP/MySQL tutorials I've looked at use any code like this and it makes my page look messy!?<pre id=code><font face=courier size=2 id=code>function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 != "" ? "'" . date("Y-d-m",strtotime($theValue)) . "'" : "NULL";
break;
case "time":
$theValue = ($theValue != "" ? "'" . date("H:i:s",strtotime($theValue)) . "'" : "NULL";
break;
case "datetime":
$theValue = ($theValue != "" ? "'" . date("Y-d-m H:i:s",strtotime($theValue)) . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "" ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}</font id=code></pre id=code>
___________________________________
* Sorry... how do you do that again?... *
Replies
Replied 20 Apr 2005 20:49:35
20 Apr 2005 20:49:35 Chris Charlton replied:
Ah, the famous function <i>GetSQLValueString</i> for DW's PHP_MySQL. I both like and hate this function.
It's there to clean up (semi-scrub) values that are about to be entered into your DB (MySQL). If something is a string (text) then it adds single quotes around it (<i>case "text":</i>, for integers (#'s) it's that <i>case "int"</i> which validates if something <i>is</i> a number. etc.etc.
<b>I think it realllllly needs an overhaul! There are better PHP functions to really trim that code down, in my opinion.</b>
~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
It's there to clean up (semi-scrub) values that are about to be entered into your DB (MySQL). If something is a string (text) then it adds single quotes around it (<i>case "text":</i>, for integers (#'s) it's that <i>case "int"</i> which validates if something <i>is</i> a number. etc.etc.
<b>I think it realllllly needs an overhaul! There are better PHP functions to really trim that code down, in my opinion.</b>
~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>