Hi.. Im a little confused.. I was trying to make a OO code from som simple PHP code. Only thing it does. is to connect to a mdb access file and gets the name..
In non OOP the code works fine.. It is as if it can't connect to the database when im using OOP?
Heres my code :
This dosen't work though it's pretty much the same as non oop code.. It dies, if i put Die on the database opening.
But the connection is the "same" as in this code :
In non OOP the code works fine.. It is as if it can't connect to the database when im using OOP?
Heres my code :
Code:
<?
class MyConn
{
// Function for opening my database
function NOpenDB()
{
echo("OOP:<br />");
$this = new COM('ADODB.Connection');
$this->open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" . realpath("TestDB.mdb"));
}
// Function to write out data
function NWriteData()
{
$SQLGetDataQuery = "SELECT * FROM TestTB";
$RSData = $this->Execute($SQLGetDataQuery);
while (!$RSData->EOF):
echo $RSData->Fields['Navn']->Value;
$RSData->MoveNext();
endwhile;
$RSData->Close();
}
// Function to close my database connection
function NCloseDB()
{
$this->Close();
}
}
$objMyConn = new MyConn;
$objMyConn->NOpenDB();
$objMyConn->NWriteData();
$objMyConn->NCloseDB();
?>
But the connection is the "same" as in this code :
Code:
<?
$MyConn = new COM('ADODB.Connection');
$MyConn->open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" . realpath("TestDB.mdb"));
$SQLGetDataQuery = "SELECT * FROM TestTB";
$RSData = $MyConn->Execute($SQLGetDataQuery);
echo("Non OOP:<br />");
while (!$RSData->EOF):
echo($RSData->Fields['Navn']->Value . "<br />");
$RSData->MoveNext();
endwhile;
$RSData->Close();
$MyConn->Close();
?>
The last one worked.!?
Anybody got any idea, why it won't connect to the database.?
I've dosn't seem to be able to figure this out myself.. But Ill keep on trying.
Thnx
Machine code Rocks:-)
[URL unfurl="true"]www.nightsoft.dk[/URL]