PHP to D3

If you want to program your website in PHP and just call some D3 functions then the Web Application Server from Pathfinders Software is for you.

Programmers Documentation

There are 3 basic ways to access D3

  • Direct call which returns raw text back to PHP.
    Useful for sending raw html to be inserted into a web page
  • Template Filling
    Useful for merging data fields from D3 into an existing html page. This method is great when you have separate web designers and D3 programmers.
  • PHP array filling from D3 data
    Useful if you just want an array of data returned from D3 and converted to a PHP array. Good for building drop down boxes based on D3 data.
    There are 2 kinds of arrays that can be returned: numeric keyed arrays and string keyed (named) arrays.

See the full list of object oriented commands.

Sample Pick Basic Program that returns a PHP array

01 SUBROUTINE FLAVORS.SUB(FDLIST, ROOTLIST, FORM, ENV, REPLY)
02 INCLUDE HDR.INCLUDE
03 FLAVORS = "CHERRY1":VM:"CHERRY2":VM:"CHERRY3"
04 FLAVORS<-1> = "BANANA"
05 FLAVORS<-1> = "GRAPE"
06 FLAVORS<-1> = "LEMON"
07 CALL FILLARRAY(FLAVORS,REPLY)
08 RETURN

The above program would return this PHP array:

Array
(
    [0] => Array
        (
            [0] => CHERRY1
            [1] => CHERRY2
            [2] => CHERRY3
        )

    [1] => BANANA
    [2] => GRAPE
    [3] => LEMON
)

Here’s the PHP code that generated the above output:

require "./d3class.php";
$d3 = new d3("localhost", 9001, 9009);
$flavors = $d3->fill_array("FLAVORS.SUB", $_GET);
print_r($flavors);

Pick Basic Program that returns a named PHP array

01 SUBROUTINE READ_USER.SUB(FDLIST, ROOTLIST, FORM, ENV, REPLY)
02 *******************************
03 * Read the webuser record     *
04 * Return named array elements *
07 *******************************
08 INCLUDE HDR.INCLUDE
09 USERID = ""
10 REC = ""
11 USER = ""
12 FCOUNT = DCOUNT(FORM,AM)
13 FOR I = 1 TO FCOUNT
14   IF FORM<I,1> = "userid" THEN
15     USERID = FORM<I,2>;
16   END
17 NEXT I
18 IF USERID NE "" THEN
19   READ REC FROM FDLIST(USER.FILE),USERID ELSE REC = ""
20 END
21 *
22 USER<-1> = "userlogin":VM:USERID
23 USER<-1> = "password":VM:REC<1>
24 USER<-1> = "securitylevel":VM:REC<2>
25 USER<-1> = "email":VM:REC<4>
26 USER<-1> = "lockout":VM:REC<5>
27 USER<-1> = "firstname":VM:REC<6>
28 USER<-1> = "lastname":VM:REC<7>
29 USER<-1> = "title":VM:REC<8>
30 CALL FILLKEYEDARRAY(USER,REPLY)
31 RETURN

The above program would return this PHP array:

Array
(
    [userlogin] => bjones
    [password] => fyi453
    [securitylevel] => 5
    [email] => bjones@jones.com
    [lockout] => N
    [firstname] => Bob
    [lastname] => Jones
    [title] => Sales Manager
)

Example Using Merge data features

Here’s how you can use the D3 object class to merge fields into an html template without connecting to a D3 server.

 

$arr = array();
$arr['name'] = "Bob Jones";
$arr['address1'] = "101 Main St.";
$arr['city'] = "San Francisco";
$arr['state'] = "CA";
$arr['zip'] = "94115";
$d3->set_all_fields($arr);
$d3->merge_data("user.txt");