Ogugua Belonwu
Ogugua Belonwu

Reputation: 2141

Problem with mysqli num rows

I have a function i use for selecting from the database

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

When i run my query:

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

I get this error message:

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

Please what am i not doing right?

Thanks

Upvotes: 1

Views: 1781

Answers (1)

Haim Evgi
Haim Evgi

Reputation: 125486

Use it like

$resultobj->num_rows() 

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

Upvotes: 1

Related Questions