benphp Posted April 11, 2008 Share Posted April 11, 2008 I've been looking for a solution to this for hours - can someone help? I'm using MS Access as the db DSN-Less, and my SQL looks like this: function fnOpenDbConn() { $db_Conn = new COM("ADODB.Connection"); $db_connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".$_SERVER['DOCUMENT_ROOT']."/Evaluation/db/eval.mdb;Uid=;Pwd=;DefaultDir=".$_SERVER['DOCUMENT_ROOT']."/Evaluation/db"; $db_Conn->open($db_connstr); return $db_Conn; } //end fnOpenDbConn $sqlc = "SELECT c_instructor FROM evaluations WHERE c_instructor = $pid "; $rSc = $dbConn->execute($sqlc); $rSc->Close(); $rSc = null; $dbConn->Close(); $dbConn = null; All I want to do is count the returned rows. I've tried this: $num_rows = $rSc->Fields->count(); which returns "1". and this: $num_rows = array($rSc); $num_rows = count($num_rows); which also returns "1". This would be easy in MySQL. Link to comment https://forums.phpfreaks.com/topic/100706-ms-access-how-to-count-rows/ Share on other sites More sharing options...
craygo Posted April 11, 2008 Share Posted April 11, 2008 looks like you are using some kind of class to do it. You would have to post the code for the class to help you out. Ray Link to comment https://forums.phpfreaks.com/topic/100706-ms-access-how-to-count-rows/#findComment-515060 Share on other sites More sharing options...
benphp Posted April 11, 2008 Author Share Posted April 11, 2008 The code I posted does it all. function fnOpenDbConn() { $db_Conn = new COM("ADODB.Connection"); $db_connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".$_SERVER['DOCUMENT_ROOT']."/Evaluation/db/eval.mdb;Uid=;Pwd=;DefaultDir=".$_SERVER['DOCUMENT_ROOT']."/Evaluation/db"; $db_Conn->open($db_connstr); return $db_Conn; } //end fnOpenDbConn $dbConn = fnOpenDbConn(); $sqlc = "SELECT c_instructor FROM evaluations WHERE c_instructor = $pid "; $rSc = $dbConn->execute($sqlc); $num_rows = $rSc->Fields->count(); print "$num_rows"; $rSc->Close(); $rSc = null; $dbConn->Close(); $dbConn = null; Link to comment https://forums.phpfreaks.com/topic/100706-ms-access-how-to-count-rows/#findComment-515064 Share on other sites More sharing options...
craygo Posted April 11, 2008 Share Posted April 11, 2008 Well you have to be pointing somewhere to a class, either on another page or some include, because $rSc don't exist on its own. I see $dbConn in your script here but not $rSc. Ray Link to comment https://forums.phpfreaks.com/topic/100706-ms-access-how-to-count-rows/#findComment-515089 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.