2012-07-25 23 views
0

這是一個我試圖解決的報告錯誤,客戶端剛剛從PHP V-whoknowswhat升級到PHP V5.3,從PHP升級到 。我相信這個錯誤是這個網站混亂的許多原因之一。無論如何,長話短說, 我需要傳遞$ params作爲參考,而不是作爲一個值,但我很困惑如何做到這一點?也許一些 幫助?PHP升級導致MYSQLI通過引用錯誤

參數2至mysqli_stmt :: bind_param()預計將是一個參考,在../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(); 

    } 

這裏的bug報告,我想偷懶的方法,它談論它只是whitescreened我沒有錯誤=(

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

+0

$ params在輸入代碼之前包含什麼? – gview 2012-07-25 23:36:44

+0

@gview用輸出更新 – ehime 2012-07-25 23:51:13

+0

bind_param想要的是參數1之後的變量列表。在內部,它將結果集綁定到變量,以便在獲取時將被更新而無需執行任何其他操作。您不能傳入代碼需要綁定變量的字符串常量數組。我假設這是爲了提供通用包裝而編碼的,無論查詢的類型如何,都會重複使用相同的代碼。出於這個原因,我毫不猶豫地給你一個解決方案,可能適用於看起來像是插入或更新的內容,但對於某個選擇而言,這根本不起作用。我會修改課程。 – gview 2012-07-26 00:53:28

回答

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; 
} 
相關問題