2011-09-13 82 views
0

錯誤的參數計數我創建了一個功能,我打算在運行我的查詢中使用:問題與mysqli的

function selectquery ($sql, $params) 
    { 
     $connection = getConnect(); 
     $result = $connection->prepare("$sql"); 
     $result->bind_param($params); 
     $status = $result->execute(); 
     $return=array('obj'=>$result, 'status' => $status, 'data'=>array()); 
     $meta = $connection->result_metadata(); 
     while ($field = $meta->fetch_field()) 
     { 
      $parameters[] = &$row[$field->name]; 
     } 
     call_user_func_array(array($result, 'bind_result'), $parameters); 

     while ($stmt->fetch()) 
     { 
      $x = array(); 
      foreach($row as $key => $val) 
      { 
      $x[$key] = $val; 
      } 
      $return['data'][] = $x; 
     } 
     $result->close(); 
     return $return; 
    } 

這就是我如何運行我的查詢:

$resultobj=selectquery ("select id from employers where subdomain = ? ", "s, $reg_subdomain"); 

它有出現此錯誤:

警告:錯誤的參數計數mysqli_stmt :: bind_param()在/home/kju/public_html/ejjk.com/functions.php第42行

致命錯誤:在/home/kju/public_html/ejjk.com/functions.php調用未定義的方法的mysqli :: result_metadata()上線45

什麼是可能出現的問題,我怎樣才能得到它固定

感謝

回答

0

mysqli_stmt::bind_param預計2個參數,但要傳遞一個:

function selectquery ($sql, $params) . {} 
... 
selectquery("....? ", "s, $reg_subdomain" // 1 string parameter, not 2); 

// it should be 
function selectquery ($sql, $types, $params) . { 
... bind_param($sql, $types, $params); 
} 
selectquery("....? ", "s", $reg_subdomain // 2 parameters);