MS Access Functions
| From: | Stephen Kivowitz | Date: | Wed, 13 Aug 2003 19:10:58 +0000 |
| Subject: | MS Access Functions | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-20236@lists.php.net to get a copy of this message | ||
I have created these functions in an include file. I thought I would share them with you, and that
you may want to include them or something similar in a future version of PHP.
<?php
//MSAccess Functions
/* Sets the connection object.
No arguments.
Returns 0 if function does not error. */
function ACC_CONNOBJ()
{
$conn = new COM("ADODB.Connection")or die("Unable to start ADO.");
return $conn;
}
/* Sets the connection string.
Arguments:
$conn- The connection object
$db- the full path of the MS Access database, e.g. 'C:\\mydb.mdb'
Returns 0 if function does not error. */
function ACC_CONNECT($conn,$db)
{
$connobj = $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
return $connobj;
}
/* Executes a SQL statement. Any valid SQL statement should work.
Arguments:
$conn- The connection object
$ACCSQL- The SQL statement to execute.
Returns 0 if function does not error. */
function ACC_QUERY($conn,$ACCSQL)
{
$res =$conn->Execute($ACCSQL);
return $res;
}
/* Returns the total number of rows in a recordset.
Arguments:
$RS- The recordset.
Returns the total number of rows in a recordset if one or more rows are found.
Returns 0 if no records are found. */
function ACC_NUM_ROWS($RS)
{
$i=0;
$RS->MoveFirst();
while(!$RS->EOF)
{
$RS->MoveNext();
$i = $i + 1;
}
if ($i<1)
{
$i=0;
}
return $i;
}
/* Returns the value of the field specified.
Arguments:
$RS- The recordset.
$RecNo- The record number. (Not an index.)
$RSField- The field name.
Returns the value of the field specified if the length of the field is greater than 0.
Returns "" if the value of the field is null or empty. */
function ACC_RESULT($RS,$RecNo,$RSField)
{
$newval = "";
$RecNo = $RecNo - 1;
$RS->MoveFirst();
$RS->Move($RecNo);
$newval = $RS->Fields[$RSField]->Value;
if (strlen($newval)<1)
{
$newval = "";
}
return $newval;
}
?>
Stephen Kivowitz
OASIS Application Development Group
College of Arts and Sciences
kivowitz@email.unc.edu
(919)843-3611