note 80119 modified in mysqli.stmt-bind-param by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Nov 2008 22:29:15 +0000 |
| Subject: | note 80119 modified in mysqli.stmt-bind-param by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147348@lists.php.net to get a copy of this message | ||
Small correction. This version removes the NULL element from the array, so it doesn't fall on
to the next ? when passed to mysql_stmt_bind_param(). Note that $saParams is still passed by
reference, but now it is being modified.
<?php
function preparse_prepared($sQuery, &$saParams)
{
$nPos = 0;
$sRetval = $sQuery;
foreach ($saParams as $x_Key => $Param)
{
//if we find no more ?'s we're done then
if (($nPos = strpos($sQuery, '?', $nPos + 1)) === false)
{
break;
}
//this test must be done second, because we need to increment offsets of $nPos for each ?.
//we have no need to parse anything that isn't NULL.
if (!is_null($Param))
{
continue;
}
//null value, replace this ? with NULL.
$sRetval = substr_replace($sRetval, 'NULL', $nPos, 1);
//unset this element now
unset($saParams[$x_Key]);
}
return $sRetval;
}
?>
--was--
Small correction. This version removes the NULL element from the array, so it doesn't fall on
to the next ? when passed to mysql_stmt_bind_param(). Note that $saParams is still passed by
reference, but now it is being modified.
<?php
function preparse_prepared($sQuery, &$saParams)
{
$nPos = 0;
$sRetval = $sQuery;
foreach ($saParams as $x_Key => $Param)
{
//if we find no more ?'s we're done then
if (($nPos = strpos($sQuery, '?', $nPos + 1)) === false)
{
break;
}
//this test must be done second, because we need to increment offsets of $nPos for each ?.
//we have no need to parse anything that isn't NULL.
if (!is_null($Param))
{
continue;
}
//null value, replace this ? with NULL.
$sRetval = substr_replace($sRetval, 'NULL', $nPos, 1);
//unset this element now
unset($saParams[$x_Key]);
}
return $sRetval;
}
?>
http://php.net/manual/en/mysqli.stmt-bind-param.php