douchengfei3985 2011-09-13 22:42
浏览 81
已采纳

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 2011-09-13 22:52
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划