0

这是我正在尝试解决的报告错误,客户端刚刚从 PHP V-whoknowswhat 升级到 PHP V5.3。我相信这里的这个错误是造成网站混乱的众多错误之一。无论如何,长话短说,我需要将 $params 作为参考而不是作为值传递,但我很困惑该怎么做?也许有些帮助?

mysqli_stmt::bind_param() 的参数 2 应为参考,在 ../Zend/Db/Statement/Mysqli.php 中给出值

public function _execute(array $params = null)
{

var_export ($params);
// output1: array ( )
/* output2: array ( 
     0 => '34',
     1 => 'Four Seasons Seattle',
     2 => 'Four Seasons Seattle',
     3 => '{//...copy text...}',
     4 => '1',
     5 => '1',
     6 => 'four-seasons-hotel',
     7 => '14',
)
*/

    if (!$this->_stmt) {
        return false;
    }
    // if no params were given as an argument to execute(),
    // then default to the _bindParam array
    if ($params === null) {
        $params = $this->_bindParam;
    }


    // send $params as input parameters to the statement
    if ($params) {
        array_unshift($params, str_repeat('s', count($params)));

var_export ($params);
// output1: array ( )
/* output2: array ( 
     0 => 'ssssssss',
     1 => '34',
     2 => 'Four Seasons Seattle',
     3 => 'Four Seasons Seattle',
     4 => '{//...copy text...}',
     5 => '1',
     6 => '1',
     7 => 'four-seasons-hotel',
     8 => '14',
)
*/
        call_user_func_array(
            array($this->_stmt, 'bind_param'),
            $params
        );
die();

    }

这是错误报告,我尝试了它所说的懒惰方式,它只是白屏了我而没有错误=(

https://bugs.php.net/bug.php?id=43568

4

1 回答 1

0

答案是完全重写 bindParams 函数以通过引用传递值。代码如下。

private static function _bindParams(&$stmt, $valuesArray)
{
    if (count($valuesArray) > 0)
    {

        $types = str_repeat('s', count($valuesArray));
        $params = array_merge(array($types), $valuesArray);

        $tmpArray = array();
        foreach ($params as $i => $value)
        {
            $tmpArray[$i] = &$params[$i];
        }

        $bindOK = call_user_func_array(array($stmt,'bind_param'), $tmpArray);
    }
    else
    {
        $bindOK = true;
    }
    return $bindOK;
}
于 2012-07-26T15:43:20.173 回答