Solved

how to create Object in Php ?

Posted on 2002-07-29
7
293 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:fabriceb
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

744 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

10 Experts available now in Live!

Get 1:1 Help Now