×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
Rob,
This would likely be more appropriate for web400, but I'm subscribed to both and this should be the droids your looking for.
As suggested you can use built in PHP functions to check the data type of variables. I suggest reviewing your options at this link here:
http://php.net/manual/en/book.ctype.php
With some additional 'if' clauses you can decide if single quotes should be added or not.
On a side note, I suggest you use parameterized queries when building your query strings. In additional to greatly reducing the chance of SQL injection, you also do not need to add single quotes for any values you want to insert (IE: around the question marks).
You can find more on the subject with examples here:
http://php.net/manual/en/function.db2-prepare.php
http://php.net/manual/en/function.db2-execute.php
But just to take some of the code you provided and show you what it might look like like (for parameterized queries, not type checking):
Note*: This code isn't tested, I just modified it off the cuff. Also, I'd personally be more consistent with my double and single quotes, but whatever works for you.
function MakeSets( $aSet ) // Convert Associative Array Into UPDATE SET Field = Value Pairs {
$sSets = $sSep = '' ;
foreach ( $aSet as $sK => $sV )
{
$sSets .= $sSep . '"' . $sK . '"' . " = ? " ;
$params[] = $sV;
$sSep = ', ' ;
}
$returnValue['query'] = $sSets;
$returnValue['params'] = $params;
return $returnValue;
}
$sets = MakeSets($data);
$stmt = db2_prepare($conn, $sets['query']);
$result = db2_execute($stmt, $sets['params']);
As an Amazon Associate we earn from qualifying purchases.