Product Documentation

FairCom SQL for PHP

Previous Topic

Next Topic

Compile PHP and the PHP PDO Extension (Windows)

To compile PHP, and compile and install the FairCom DB PHP PDO extension on Windows, follow the steps in this section.

Step 1: Build PHP 7 and the PDO extension

  1. Download the PHP 7 SDK from https://github.com/Microsoft/php-sdk-binary-tools (you do not need a GitHub account to do this. Just press the green “Code” button and select “Download ZIP”)
  2. Once the file has downloaded (it will have a name like “php-sdk-binary-tools-master.zip”), extract its contents into the root folder of your C: drive (C:\). This will cause a “C:\php-sdk-binary-tools-master” folder to appear. Rename this folder to “C:\php-sdk”.
    You have done this step correctly if your “C:\php-sdk” folder contains a handful of “phpsdk-____.bat” files in it (as well as other folders and files).
  3. Decide which version of PHP 7 you are going to use. Different versions of PHP 7 are associated with different versions of the Microsoft Visual Studio compiler:

    Visual C++ 14.0 (Visual Studio 2015) - PHP 7.1
    Visual C++ 15.0 (Visual Studio 2017) - PHP 7.2, PHP 7.3 or PHP 7.4
    Visual C++ 16.0 (Visual Studio 2019) - the master PHP branch

    Also decide if you are going to use the “master” PHP branch or not. Both of these decisions will affect steps that follow…
    These instructions do not support PHP 7.0, because 7.0 requires an earlier version of the SDK.
  4. Open a Developer Command Prompt window for the version of Microsoft Visual Studio you selected in the previous step. Typically, this is available from the Start menu, following a path similar to:
    Visual Studio 2017 > X64 Native Tools Command prompt for VS 2017 where 2017 is your version of Visual Studio and X64 is for a 64-bit version of your FairCom product. Use X86 for 32-bit versions of your FairCom product. Warning - the Developer Command Prompt Start menu entries which do not specify a bit depth actually open the 32-bit version of the Developer Command Prompt. For more details, see the Microsoft Developer Command Prompt (https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line) web page.
  5. In the Developer Command Prompt window, move to the C:\php-sdk folder that you created in step 2:
    C:
    cd \php-sdk
  6. Still in the Developer Command Prompt window, execute the “phpsdk-______.bat” file that corresponds to the version of Visual Studio you selected and the bit depth of your FairCom product. Here is a typical listing of the available batch files:

    phpsdk-vc14-x64.bat
    phpsdk-vc14-x86.bat
    phpsdk-vc15-x64.bat
    phpsdk-vc15-x86.bat
    phpsdk-vs16-x64.bat
    phpsdk-vs16-x86.ba

    vc14/vc15/vs16 - the version of Microsoft Visual Studio you selected in step 3
    x64/x86 - the bit depth of your FairCom product - “x64”=64 bits, “x86”=32 bits
    After executing the batch file, the command prompt should have changed to a “$”:
  7. Still in the Developer Command Prompt window, execute one of the following commands:
    phpsdk_buildtree phpdev
    phpsdk_buildtree master
    The second command is used only if you decided to use the “master” branch of PHP in step 3.
    Depending on which batch file you ran in this step, a “phpdev” or “master” folder tree will have been created in your C:\php-dev folder, and you will have been moved into a “working folder” in that folder tree. Make note of the working folder (“C:\php-sdk\phpdev\vc15\x64” in the following image), you will be unzipping a TAR file into it in step 9.



    In the image above, the “working folder” is shown to be “C:\php-sdk\phpdev\vc15\x64”, where “phpdev” or “master” depends on the decision you made in step 3. This working folder contains exactly one child folder - “deps”
  8. Go to https://www.php.net/downloads and download the version of PHP that you selected in step 3. Do not follow the “Windows downloads” link, because this leads to ZIP files which do not contain the source code that we need to build from source. Only the tar files contain the source code we need. Depending on what version of PHP you are downloading, you might have to follow the “Old archives” link at the right-hand side of the page. The tar files are available in three different compression formats: bz2, gz, and xz. Feel free to choose any of them. The freely-available, open source 7zip program can be used to unzip any of them. Assuming that you chose the bz2 compression format, your file will have a name like this, where the text before ".tar.bz2" is the version of PHP 7 that you chose. For example, php-7.4.8.tar.bz2.
  9. Once the download is complete, open the tar file with a file decompressor and open the first folder (the .tar archive). This should show a single folder, which has the same name as the PHP version shown in the previous step (“php-7.4.8” in this example). Drag that PHP folder into the “working folder” discussed in step 7 ( “C:\php-sdk\phpdev\vc15\x64” in this example). At this point, your “working folder” should contain two folders - the original “deps” folder and your new PHP folder which came from the tar file. The new PHP folder contains the source code of PHP.
  10. Back in the Developer Command Prompt window, change into the new PHP folder you just created and filled from the tar file. You will probably need to change the version in the following to match the PHP version above:
    cd php7-.4.8
  11. Download & extract the source code of all of the PHP dependencies by executing the following command (if you are not using the “master” branch) in the Developer Command Prompt:
    phpsdk_deps -u
    If you are using the “master” branch, append “-b master” to the end of the above command, as follows:
    phpsdk_deps -u -b master
    The process may take a few minutes. It should finish with a “successful” message, such as “Updates performed successfully”. Note that it might display an "INFO:" notification like the following. This is OK and can be ignored:
    "INFO: Could not find files for the given pattern(s)."
  12. Still in the Developer Command Prompt, run the following based on the FairCom product you are using (where <basedir> is the full path of your FairCom product installation directory):
    c-treeACE
    buildconf --force --add-modules-dir=<basedir>\sdk\sql.php.pdo
    c-treeRTG
    buildconf --force --add-modules-dir=<basedir>\Driver\sql.php.pdo
    c-treeEDGE
    FairCom-DB
    FairCom-EDGE
    FairCom-RTG
    buildconf --force --add-modules-dir=<basedir>\drivers\php.sql.pdo
    You should get a message about adding the specified folder to the module search path.
  13. Now run the following command, still in the Developer Command Prompt, with <basedir> changed as in the previous step:
    configure --disable-all --disable-zts --enable-pdo --enable-cli --enable-cgi --enable-object-out-dir=.. --disable-ipv6 --with-pdo-ctsql=shared,<basedir>
    This will check a bunch of stuff and print lots of configuration information. There should be no warnings or error messages, and it should end by telling you to “Type 'nmake' to build PHP”.
    If you get the following warning, it means the “add-modules-dir” you used in step 12 was incorrect. Please go back to step 12 and verify that the folder exists.
    Unknown option --with-pdo-ctsql;
    If you get the following warning, it means the <basedir> folder you specified in the “configure” command (in this step) is incorrect.
    WARNING: ctreesql not enabled; libraries and headers not found
    You know this step worked correctly if you see something like the following in the output, which indicates the our PHP PDO extension was found and enabled:|
    Enabling extension __________\drivers\php.sql.pdo\src
    The last box of configuration information that is printed should have “Thread Safety” shown as “No”. That is the purpose of the “--disable-zts” flag (“Zend Thread Safety”). If “Thread Safety” is still shown as “Yes”, then add “--disable-maintainer-zts” flag to the 'configure' command you ran at the start of this step as well. We are turning off thread safety because we are using IIS + FastCGI, and this combination requires thread safety to be turned off.
  14. Make the PHP and PHP PDO extension by running the following command in the Developer Command Prompt:
    nmake
    There will likely be many compiler warnings as PHP is built, but they can be ignored.
    Once PHP is built, a message should return confirming its completion.
  15. Still in the Developer Command Prompt, make sure a new “Release” folder has appeared in the “working folder”:
    dir ..
    The folder should be called “Release”. If there is no “Release” folder, but there is a “Release_TS” folder, it means that Thread Safety was not turned off in step 13. The “Release” folder should contain the “php.exe” application you just built in step 14. Now copy one of the INI file templates from the current folder into that Release folder, using the following command:
    copy php.ini-development ..\Release\php.ini
    Make a note of this “Release” folder’s full path, because you will need it in subsequent steps of these instructions, and you will need it in step 4 of the “Configure Microsoft IIS” instructions.
  16. Use a text editor to open the php.ini file you just created and search for lines ";extension_dir"
  17. Un-comment one of them by removing the leading semicolon, and change the line so the directory is the Release folder that contains the INI file and "php.exe". For example, the line should now read something like "extension_dir = "C:\php-dev\phpdev\vc15\x64\Release""
  18. Find the section of the INI file that contains the commented-out list of extensions and find the line for “pdo_mysql”
  19. Make a copy of that line then remove the leading semicolon, and change it to “pdo_ctsql". Be sure to save the INI file after you have finished making your changes.
    Note: If you are using PHP7.1.33, the extension line reads something like "extension=php_pdo_ctsql.dll"
  20. Copy the “ctsqlapi.dll” file from the appropriate FairCom product folder to the “Release” folder that contains the INI file you just edited and “php.exe”. You can find “ctsqlapi.dll” in the following folder, where <basedir> is the full path of your FairCom product installation directory:
    c-treeACE
    <basedir>\bin\sql.direct\
    c-treeRTG
    <basedir>\bin\sql.direct\
    c-treeEDGE
    FairCom-DB
    FairCom-EDGE
    FairCom-RTG
    <basedir>\drivers\ctree.drivers\lib\
  21. Back in the Developer Command Prompt, verify that PHP built correctly and the extension loads correctly by first changing into the Release folder and then running the PHP version command:
    cd ..\Release
    php -v
    Upon completion, version information should be printed with no error messages. If there are error messages about being unable to load dynamic library 'pdo_ctsql', then there was likely an issue in steps 15-21.
  22. At this point, you can test the c-tree PHP PDO tutorials from the command line as follows:
    c-treeACE
    php -f <basedir>\sdk\sql.php.pdo\tutorials\PHP_Tutorial1.php
    c-treeRTG
    php -f <basedir>\Driver\sql.php.pdo\tutorials\PHP_Tutorial1.php
    c-treeEDGE
    FairCom-DB
    FairCom-EDGE
    FairCom-RTG
    php -f <basedir>\drivers\php.sql.pdo\tutorials\PHP_Tutorial1.php
    It should print the HTML source code of a web page. If an “ ctsqlConnect: -20212 Error in Network Daemon” error is shown, it means the c-tree server is not running. Start the c-tree server and re-do this step. Here is what the correct output of this command should look like:
    <html>
    <head>
    <title>PHP Tutorial 1</title>
    </head>
    <body>
    <h4>INIT</h4>
    Logon to server...<br>
    <h4>DEFINE</h4>
    Create table...<br>
    <h4>MANAGE</h4>
    Delete records...<br>
    Add records...<br>
    Display records...<br>
    <TABLE border=1>
    <TR><TH>Number</TH><TH>Name</TH></TR>
    <TR><TD>1000</TD><TD>Bryan Williams</TD></TR>
    <TR><TD>1001</TD><TD>Michael Jordan</TD></TR>
    <TR><TD>1002</TD><TD>Joshua Brown</TD></TR>
    <TR><TD>1003</TD><TD>Keyon Dooling</TD></TR>
    </TABLE>
    <h4>DONE</h4>
    Logout...<br>
    </body>
    </html>
    If you wish, you can repeat this step for each of the four PHP tutorials
    Additional details about how to build PHP can be found at this URL: https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2
    Note: the instructions above do not follow that web page exactly.

TOCIndex