Jump to content

Have FileMaker serve PHP?


IrongateMachine
 Share

This topic is 6569 days old. Please don't post here. Open a new topic instead.

Recommended Posts

On this note, has anyone here got FX & php running on a stand-alone Mac (OS 10.3.2). I've got PHP running. I can open a .php page, using a self IP# (http://127.0.0.1/~fej/). But I cannot get the FX examples to show anything at all. I'm not sure whether I'm an idiot (quite likely) or whether I'm up against a networking impossibility.

Basically, Apache is using port 80. FileMaker Web Companion is using port 591. The question is, "Is it possible to run, for learning/testing, FX php on 1 machine?"

If so, what IP address do you enter in the FX server_data.php page? I have:

$serverIP = '127.0.0.1';

$webCompanionPort = '591';

I know very little about this stuff, yet.

Link to comment
Share on other sites

Yes, you should be able to run Apache, PHP, FileMaker, and Web Companion all on the same machine. Try something like:

$q = new FX("127.0.0.1", "591");

$q->SetDBData("test.fp5", "myLayoutName");

$q->SetDBPassword("myPassword");

$r = $q->FMFindAll();

print_r($r);

The server_data.php page is relatively new (or at least, not in the older version of FX that I'm still using wink.gif ), so I'm not as familiar with it. Have you included it in your page prior to making the FX call? You can include it with require_once(server_data.php);

Link to comment
Share on other sites

By the way, print_r() is very useful - it prints out whatever object you pass to it in a very nicely formatted manner. It is great for debugging when you want to see what one of your objects looks like at a given point. The best way to look at the output of print_r() is to "view source" on the resulting HTML. The formatting of print_r() is designed for legibility in the resulting HTML code, not for legibility in the browser window.

Link to comment
Share on other sites

I finally got it to work, by substituting some data directly in, rather than using the variables on Chris's example file.

This worked:

include_once("./FX/FX.php");

$BookQuery = new FX("127.0.0.1", "591");

$BookQuery->SetDBData("Book_List.fp5", "Book_List");

This (his original, incl. comments) did not:

include_once($HTTP_SERVER_VARS['DOCUMENT_ROOT'] . "/FX/FX.php"); // FX.php contains the class for pulling data

// from FileMaker into PHP -- 'include_once()' makes sure the class is only declared once.

include_once($HTTP_SERVER_VARS['DOCUMENT_ROOT'] . "/FX/server_data.php"); // To make sure that these examples work for you, be sure

// to set the IP address of your server in server_data.php

$BookQuery = new FX($serverIP, $webCompanionPort); // This line creates an instance of the FX class

$BookQuery->SetDBData("Book_List.fp5", "Book_List");

It is not that the server_data.php file is wrong. Because the above fails even if I hard-code the numbers in the $BookQuery, like the one that worked.

The file "server_data.php" is in the "FX" folder at the same level, as is the file "FX.php"

server_data.php:

<?php

$serverIP = '127.0.0.1';

$webCompanionPort = '591';

?>

So this line is the problem I think:

include_once($HTTP_SERVER_VARS['DOCUMENT_ROOT'] . "/FX/FX.php");

This doesn't work either:

include_once($HTTP_SERVER_VARS['DOCUMENT_ROOT'] . "./FX/FX.php");

(added the ".", which was needed for the include to work in the hard-coded version)

Perphaps I screwed up his file, but I don't think I touched it. I'm pretty confused, but happy to be running.

Link to comment
Share on other sites

It's not you -- I remember now that I had the same problem a while ago. Ah, yes. The object

.....$HTTP_SERVER_VARS

has been replaced with

.....$_SERVER

as of PHP 4.1.0. So if you're using a version of PHP > 4.1.0, you can try:

.....$_SERVER['DOCUMENT_ROOT']

HOWEVER, it is not necessary to include the document root. It would be better to reference your files using relative paths, like this:

include once("../other_folder/FX/FX.php");

Glad to read you got it working!

Link to comment
Share on other sites

Yes, I'm using PHP 4.3.4, which I got in an excellent and simple install package for Mac OS X by Marc Liyanage (who deserves an award; he also has a simple but powerful XML/XSLT/HTML parser/renderer) at:

http://www.entropy.ch/software/macosx/php/

I still haven't got the variables to work. It's more complicated, because he's reusing these again in a complex structure, to do something about sorting also; so substituting something else must be done in several places; it's over my head ;)-|

I got it to work without the two variables at top, by hard-coding the values themselves; but I'm undoubtedly missing out whatever functionality is in the rest of the block. Since I'm a beginner, I should probably learn a more basic way to do it first anyway; and I'm sure he'll update his examples to work with 4.3.4 eventually; I believe it's a fairly new version.

Here's the whole block, with his comments:

include_once($HTTP_SERVER_VARS['DOCUMENT_ROOT'] . "/FX/FX.php"); // FX.php contains the class for pulling data

// from FileMaker into PHP -- 'include_once()'

// makes sure the class is only declared once.

include_once($HTTP_SERVER_VARS['DOCUMENT_ROOT'] . "/FX/server_data.php"); // To make sure that these examples work for you, be sure

// to set the IP address of your server in server_data.php

// IMPORTANT: The leading '$' denotes a variable in PHP

$BookQuery = new FX($serverIP, $webCompanionPort); // This line creates an instance of the FX class

$BookQuery->SetDBData("Book_List.fp5", "Book_List"); // The '->' indicates that SetDBData is part of

// the FX instance we just created.

$arrayName = 'HTTP_' . $HTTP_SERVER_VARS["REQUEST_METHOD"] . '_VARS'; // Note the '$$' a couple of lines down. I'm using a variable

// whose name is the contents of another variable. VERY handy.

if (${$arrayName}['currentSort'] != '') { // If sorting has been requested, this adds it to the query.

$BookQuery->AddSortParam($HTTP_GET_VARS['currentSort']);

}

if (${$arrayName}['currentQuery'] == 'Search Book List!') { // Check if this page is being accessed by a search

foreach ($$arrayName as $key => $value) { // 'foreach()' is a VERY handy function. It steps

// through an array and stores the data in temporary

// variables as directed ($key and $value in this case)

Link to comment
Share on other sites

I still haven't got the variables to work

Which variables? Could you explain again?

The server_data.php file is not part of the FX class. The file, "server_data.php", is not necessary to use FX completely and successfully. Think of it more like a config file or header file, where you can declare data that you will use throughout your application. Kind of like a resource or main menu file in a FileMaker solution where you have most of your globals fields.

The purpose of the "server_data" file is to allow you to define the FileMaker server IP address and Port number in one place. The code within the FX class does not at all depend on or directly reference the "server_data" file. In your own code, when you want to create an FX instance and query your FileMaker database, you have to specify the FileMaker IP address and Port number. Instead of writing the IP address over and over, you can define a global variable that contains the IP address. Then, each time you instantiate the FX class, you just pass it the global variable instead of the hard coded IP address. This makes it easy to switch from a development server to a production server -- you just switch the IP address in one place and you're good to go.

If you're having problems including the server_data file, try the following code which I tested on my system and then copy/pasted here:

[color:"666666"]<?

require_once("./FX/FX.PHP");

require_once("./FX/server_data.php");

$q = new FX($serverIP, $webCompanionPort);

$q->SetDBData("Book_List.fp5", "Detail_View");

$q->SetDBPassword("myPassword");

$r = $q->FMFindAll();

print_r($r);

?>

My folder structure is:

[color:"666666"]solutionFolder

---myTest.php

------FX

---------FX.php

---------server_data.php

---------Book_List.fp5

Re:

but I'm undoubtedly missing out whatever functionality is in the rest of the block

Which block are you talking about?

All the FX functionality is encapsulated in the single FX.php file. If you only include FX.php and delete the rest of the files, you're still getting all the functionality that FX offers. (OK, there is a little extra functionality for caching FileMaker data in MySQL, hidden in the phpcache folder. But that is another story.)

I'd like to see you get this working. Let me know how it goes for you.

Link to comment
Share on other sites

Upon further review, the following line of code from Chris' example might also be subject to PHP version problems:

$arrayName = 'HTTP_' . $HTTP_SERVER_VARS["REQUEST_METHOD"] . '_VARS'

The code to the right of the equal sign basically equates to "HTTP_GET_VARS" or "HTTP_POST_VARS". These are built-in/pre-defined variables that every PHP script contains by default. They are associate arrays that return the values submitted by the user during the request for the current page. So if I submitted a GET request like:

http://server.com/test.php?myName=mariano&yourName=fenton

Then HTTP_GET_VARS['myName'] would equal "mariano".

the HTTP_GET_VARS and HTTP_POST_VARS variables are now deprecated and have been replaced by the much simpler $_GET and $_POST. Notice that there are two separate variables for the two main submit methods: GET and POST. This can be ackward because you may not know how the request was issued. There is another predefined variable, $_REQUEST, which returns the variables submitted by both the GET and the POST methods. This is much easier to work with. So using $_REQUEST, we could access myName using $_REQUEST['myName'] and get back "mariano".

Check out the following super simple but useful script which prints out all the parameters provided in the request:

<?

foreach ($_REQUEST as $i) {

	print ($i."<br>");

}

?>



Anyway, you should be able to change the following lines:


$arrayName = 'HTTP_' . $HTTP_SERVER_VARS["REQUEST_METHOD"] . '_VARS';

if (${$arrayName}['currentSort'] != '')

   $BookQuery->AddSortParam($HTTP_GET_VARS['currentSort']);

}

if (${$arrayName}['currentQuery'] == 'Search Book List!')

   foreach ($$arrayName as $key => $value) {




To:


if ($_REQUEST['currentSort'] != '')

   $BookQuery->AddSortParam($_REQUEST['currentSort']);

}

if ($_REQUEST['currentQuery'] == 'Search Book List!')

   foreach ($_REQUEST as $key => $value) {

Hope this helps!

Link to comment
Share on other sites

It's fine. I'm sorry to waste so much bandwidth because of my limited knowledge. But hey, I'm usually not such an idiot ;)-)

The problem was that I was not following to the letter the instructions for installation of FX. He says clearly "Put the FX folder at the root level of your web server."

Mac OS X lets you put web pages into your user home "Sites" folder for web serving; php pages work from there also. That's the default for a user. But, running a info() test on the php installation shows clearly that the real 'root' folder is /Library/WebServer/Documents.

If I put the FX folder in there then his location variables work. One is always a bit cautious about putting things in the Library folder; I didn't really know that folder existed, having never gone there before. It's more a Mac OS X misunderstanding.

Now that I know, I can use either form of addressing. I also see why he did it this way. It makes the php pages more portable, to any other system. /~short user name/FX/FX.php is not so portable (though easily batch replaced with a text editor).

I also see that the other variables, such as:

$arrayName = 'HTTP_' . $HTTP_SERVER_VARS["REQUEST_METHOD"] . '_VARS';

work fine in either place, since they are not being used to specify a location, but are getting php constants.

I'm not entirely sure about the difference between $HTTP_SERVER_VARS and just $_SERVER. It appears to be a version upgrade change in php, $_Server being more global or something. But both work for me in PHP 4.3.4.

And Anatoli is right in a way. I probably should have learned Lasso already, like years ago; and I may yet. But, I'm just inching along with web stuff; it's a sideline which I seldom use (for obvious reasons). I know some CDML, a little JavaScript, some XML, some AppleScript, so now I'm trying PHP. MySQL will be next; unless the mythical FM 7 is many times faster and more powerful (dream on).

Link to comment
Share on other sites

BTW, MySQL is now part of Lasso and it is the fully licensed MySQL. All the security and session management is build into Lasso with the help of MySQL. Lasso is IMHO still the best for FM driven website, but now can be any combination with MySQL. Imagine to do all temporary processing for shopping basket in Lasso/MySQL and when finalized order is placed Lasso will post that order into FM company wide solution.

Of course that can be done also with PHP.

Link to comment
Share on other sites

Touche! wink.gif But then again, the demo files that come with the FX module are written for an older version of PHP (a few years old now). You'd experience the same problem if you tried to run Lasso 3.6 code on a new installation of Lasso 7. =) Still, good point - Lasso is somewhat easier to install and get going with.

On a separate note, relative addresses are usually more portable than absolute addresses. For instance, [color:"silver"]"./FX/server_data.php" is more likely to work if you move your application folder to another server than [color:"silver"]$HTTP_SERVER_VARS['DOCUMENT_ROOT'] . "/FX/FX.php" -- for the reason you cited above (~user/FX/...). Also, I believe that relative addresses can be resolved more quickly than absolute addresses which require the [color:"silver"]$HTTP_SERVER_VARS or [color:"silver"]$_SERVER variable to be queried.

Link to comment
Share on other sites

This topic is 6569 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.