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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.