Solved

how to create Object in Php ?

Posted on 2002-07-29
7
324 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:Richard Quadling
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:Richard Quadling
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:Richard Quadling
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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:Richard Quadling
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:
Richard Quadling 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

713 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