Jump to content

MS Access - how to count rows?


benphp

Recommended Posts

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

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.