note 36079 added to function.odbc-num-rows

From: Date: Thu, 25 Sep 2003 04:16:53 +0000
Subject: note 36079 added to function.odbc-num-rows
Groups: php.notes 
Request: Send a blank email to php-notes+get-57080@lists.php.net to get a copy of this message
Using odbc_num_rows() against MS SQL Server will return correct number of result if you add 'TOP' modifier in the select statement, make it too big number to make sure they will cover all possible records, it doesn't effect any performance, for example: $query="select top 100000 * from employees where dept_id=$dept_id"; instead of just: $query="select * from employees where dept_id=$dept_id"; The first statement will return the correct number of records while the latter will always return -1 if there are any records or 0 if no record at all. However if you only want to examine whether there is a record, -1 is suffice. Another solution is to use odbc_next_result() function, count for the records in first statement and follow by select statement, for example: $query="select count(*)from employees where dept_id=$dept_id;select*from employees where dept_id=$dept_id" After execute this multiple statements in a single execution, it will return multiple recordsets: $result=odbc_exec($connection,$query); # get number of records form count statement if(odbc_fetch_row($result))$record_count=odbc_result($result,1); # go to next result set odbc_next_result($result); # the code to handle next result set here... Hope this help... ---- Manual Page -- http://www.php.net/manual/en/function.odbc-num-rows.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36079 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36079&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36079&report=yes

« previous php.notes (#57080) next »