Solved

how to create Object in Php ?

Posted on 2002-07-29
7
302 Views
Last Modified: 2008-02-01
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,
0
Comment
Question by:fabriceb
  • 5
  • 2
7 Comments
 
LVL 40

Expert Comment

by:RQuadling
ID: 7185703
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

0
 
LVL 40

Expert Comment

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

Regards,

Richard Quadling.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 7185713
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:fabriceb
ID: 7187348
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,
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 7187392
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.

0
 

Author Comment

by:fabriceb
ID: 7187477
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 ?
0
 
LVL 40

Accepted Solution

by:
RQuadling earned 200 total points
ID: 7187487
As long as the access application (or whatever components are needed for COM) is installed on the server, it is PHP via COM that communicates with access, not the web-server.

I use Sambar Server (www.sambar.com). In house we have IIS.

If you have a non-windows server, then you will need other tools to get the COM interface working. I don't know what they are.

If you can, I would suggest you upgrade your version of Access though. I doubt many people can offer much support on A97.


Having said that, once you've got the application opened via COM, then you need the VBA manual for Access to see what properties, methods and objects are available.

If you are not getting Version, then I am surprised!

Richard.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now