Link to home
Start Free TrialLog in
Avatar of fabriceb
fabriceb

asked on

how to create Object in Php ?

Hi,
I would like to create an object in Php. Thi Object will be ACCESS, but I can't crate it.
In ASP, it's like that :

set obj=CreateObject("Excel.Sheet")

but in Php how is it ?

Thanks,
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

This is an example using Word and PHP.

<?php
set_time_limit(0);
error_reporting(E_ALL);

$word = new COM("word.application") or die("Unable to instanciate Word");
print "Loaded Word, version {$word->Version}\n";

$word->Visible = 1;
$word->Documents->Add();

$word->Selection->TypeText("#TAG1#");
$word->Selection->TypeText("#TAG2#");
$word->Selection->TypeText("#TAG1#");
$word->Selection->TypeText("#TAG2#");

$word->Selection->Find->ClearFormatting;
$word->Selection->Find->Replacement->ClearFormatting;
$word->Selection->Find->Text = "#TAG1#";
$word->Selection->Find->Replacement->Text = "Replacement text for tag 1.";
$word->Selection->Find->Forward = True;
$word->Selection->Find->Wrap = 2;
$word->Selection->Find->Format = False;
$word->Selection->Find->MatchCase = False;
$word->Selection->Find->MatchWholeWord = False;
$word->Selection->Find->MatchByte = False;
$word->Selection->Find->MatchAllWordForms = False;
$word->Selection->Find->MatchSoundsLike = False;
$word->Selection->Find->MatchWildcards = False;
$word->Selection->Find->MatchFuzzy = False;
$word->Selection->Find->Execute(array('Replace'=>2));

$word->Documents[1]->SaveAs("C:\\test.doc");

$word->Quit();
$word->Release();
$word = null;
?>

I would try using ...

<?php
$access = new COM("access.application") or die("Unable to instanciate Access");
print "Loaded Access, version {$access->Version}\n";

$access->Quit();
$access->Release();
$access= null;
?>


This produced the output of ...

Loaded Access, version 10.0

Once Access is opened, you will need to know the Access object model, which is all available from within Access itself.

Regards,

Richard Quadling.
Oh. Something else to watch out for.

You cannot use named parameters in COM functions in PHP.

You can in VBA and Delphi.

Which means, in the word example I've shown, the line ...

$word->Selection->Find->Execute(array('Replace'=>2));

will not work.

Instead, it would need to look something like ...

$word->Selection->Find->Execute(blah,blah,blah,blah,blah,blah,2,blah,blah,blah);

or whatever. The exact sequence of parameters is needed.

I've been told that passing an associative array works, but no-one can demonstrate this working.

Regards,

Richard Quadling.
Avatar of fabriceb
fabriceb

ASKER

Ok, I think I can create an object now, but properties and methods are not all available. Why ? For example, $access->Version give me an error :
Warning: Unable to lookup Version: Nom inconnu.

Do you know where I can find all properties and methods of my Access Object. I would like to open a database and execute a macro which is save in this database.

Thanks,
What version of Access are you using?

I've got only got V10 (XP) on my machine. If you have the help installed for Access, then you will be able to use the VBA for Access help file to show you all the objects/properties/methods.

Without the help system you have no chance of doing it yourself if you don't know Access VBA.

I have ACCESS97 SR-2 and my serveur is IIS.
Someone says to me that it works on apache server.
Is it possible that it's work on IIS ?
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial