Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to create Object in Php ?

Posted on 2002-07-29
7
Medium Priority
?
341 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 600 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

782 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