mysqli num行的问题

时间:2011-09-14 09:46:51

标签: php mysql mysqli

我有一个用于从数据库中选择的功能

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

       while ( $result->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);
if ($resultobj['obj']->num_rows()>0 || in_array($reg_subdomain, $locked_subdomains)) { $error .="Subdomain already exist, please choose another <br>"; }

我收到此错误消息:

Warning: mysqli_stmt::num_rows() [mysqli-stmt.num-rows]: Couldn't fetch mysqli_stmt in /home/drac/public_html/dracxyz.com/functions.php on line 174

请问我做得对不对?

由于

1 个答案:

答案 0 :(得分:1)

一样使用它
$resultobj->num_rows() 

http://php.net/manual/en/mysqli-result.num-rows.php