2016-07-26 4 views
1

これは単純な行挿入用のコードです。 php 5.6ではうまく動作しますが、PHP 7.0.9では "mysqli_stmt_bind_param()へのパラメータ3が参照になる"というエラーが表示されます。参照することになっているmysqli_stmt_bind_param()へのパラメータ3:php5.6 vs php7

function refValues($arr) 
{ 
    if(strnatcmp(phpversion(),'5.3') >= 0) //Reference is required for PHP 5.3+ 
    { 
    $refs = array(); 
    foreach($arr as $key => $value) 
     $refs[$key] = &$arr[$key]; 
    return $refs; 
    } 
    return $arr; 
} 

... 
$sql = "INSERT INTO table (player_id,ctime) VALUES(?,?)"; 
$types = "ii"; 
$args = array(10, time()); 

$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name, $db_port, $db_sock); 
if(!$conn) 
    throw new Exception("Could not connect to mysql server"); 

$stmt = mysqli_prepare($conn, $sql); 
if(!$stmt) 
    throw new Exception("Could not prepare sql"); 

$res = call_user_func_array('mysqli_stmt_bind_param', array_merge(array($stmt, $types), refValues($args))); 
if(!$res) 
    throw new Exception("Could not bind params"); 

if(!mysqli_stmt_execute($stmt)) 
    throw new Exception("Could not execute stmt"); 

何が間違っていますか?

+0

にrefValues機能を変更しています。 – Devon

+1

私のテストから、あなたが持っているrefValues関数は参照を処理する必要があります。 7.0.5で動作します。 – Devon

+0

@Devon、ありがとう! – ivhome

答えて

1

答えは、それはあなたがarray_mergeの戻り値を使用することはできませんので、あなたは3+、それは引数のために参照するための実際の変数を提供する必要があり、参照が必要です

function refValues(&$arr) 
関連する問題