开发者

Problem with wrong parameter count in mysqli

I created a function i intent to use in running my queries:

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; 
    }

And this is how i run my query:

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

It comes up with this error:

Warning: Wrong parameter count for mysqli_stmt::bind_param() in /home/kju/public_html/ejjk.com/functions.php on line 42

Fatal error: Call to undefined method mysqli::result_metadata() in /home/kju/public_html/ejjk.com/functions.php on line 45

What is the possible problem and how can i get it fixed

Thanks


mysqli_stmt::bind_param expects 2 parameters, but you are passing one :

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜