Getting result row count using prepared statement

When using a prepared statement for a select query, I am trying to get the row count of the query result immediately after the execute.

$prep1 = $link->prepare($sql);
$prep1->execute();
$cnt = $prep1->affected_rows;

$cnt = -1 even thought there is a row returned because if I process fetch, I get the resulting row.

Is it possible to get a rowcount directly without processing fetch?

Yes, I had seen that and played with it and it does work. I guess I should have framed my question as ‘without using store_result’. But in thinking about it and reading more in general and looking at other functions, when using a prepared statement, there is no ‘result set’ like there is using query, until you fetch it row by row or store it using store_result.

I had read somewhere that there can be a pretty good performance hit by using store_result but as it says in the documentation you need to make to sure to release that result set as soon as you’re done with it. Not sure how much of a hit though.

In reality, I would use this mostly for a quick check to see if there is a certain value in a table so it would never really return a large result set anyhow.

So again, thanks for the input and steering me in the right direction.

I’m not really familiar with mysqli, but does this help?http://www.php.net/manual/en/mysqli-stmt.num-rows.php