douchengfei3985
douchengfei3985
2011-09-13 22:42

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douzi5214 douzi5214 10年前

    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);
    
    点赞 评论 复制链接分享

相关推荐