Btrieve 2
Loading...
Searching...
No Matches
Using Btrieve with PHP

Using Btrieve with PHP on Windows x64

Documented below is one approach to configuring the Btrieve 2 SDK for the PHP programming language. In this example, we will use Visual Studio 2015 to target a native Windows x64 environment. It is assumed that Zen is already installed and running.

  • Install SWIG and PHP if not already installed.
  • Install the Btrieve 2 Windows SDK for Zen.
  • Generate, build, and install Btrieve PHP.
    • Open the Visual Studio x64 Native Tools Command Prompt.
    • Change directory into the Btrieve 2 SDK directory.
    • Generate Btrieve PHP.
      • c:\swigwin-3.0.12\swig.exe -cppext cpp -outcurrentdir -php7 -c++ -Iinclude swig\btrievePhp.swig
        • Note that the path to SWIG used above may differ.
        • Note that PHP version 7 is specified.
    • Build Btrieve PHP.
      • cl -EHsc -c -Iinclude -D_ALLOW_KEYWORD_MACROS -DZEND_WIN32 -DPHP_WIN32 -DZEND_DEBUG=0 -Ic:\php-devel-pack-7.1.7-nts-win32-vc14-x64\php-7.1.7-devel-vc14-x64\include\Zend -Ic:\php-devel-pack-7.1.7-nts-win32-vc14-x64\php-7.1.7-devel-vc14-x64\include -Ic:\php-devel-pack-7.1.7-nts-win32-vc14-x64\php-7.1.7-devel-vc14-x64\include\main -Ic:\php-devel-pack-7.1.7-nts-win32-vc14-x64\php-7.1.7-devel-vc14-x64\include\TSRM btrievePhp_wrap.cpp
      • link -dll -force:multiple win64\x86_64\btrieveCpp.lib -libpath:C:\php-7.1.7-nts-Win32-VC14-x64\dev php7.lib -out:php_btrievePhp.dll btrievePhp_wrap.obj
        • Note that the path to PHP used above may differ.
    • Install Btrieve PHP.
      • copy btrievePhp.php "c:\Program Files\Actian\Zen\bin"
      • copy php_btrievePhp.dll "c:\Program Files\Actian\Zen\bin"
        • You may need elevated permissions to perform these copies.
      • Configure PHP to load Btrieve PHP.
        • Update "C:\php-7.1.7-nts-Win32-VC14-x64\php.ini" as follows:
          • Add "C:\Program Files\Actian\Zen\bin" to "include_path".
          • Add "C:\Program Files\Actian\Zen\bin\php_btrievePhp.dll" as an extension.
          • Note that the path to PHP used above may differ.
    • Execute the Btrieve PHP sample program.
      • c:\php-7.1.7-nts-Win32-VC14-x64\php.exe -f samples\btest.php x=9
        • You should see the output "{"x":9,"xSquared":81,"xSquareRoot":3}".
        • Note that the path to PHP used above may differ.
        • You may need to change the permissions of the current directory if you receive the error "Warning: assert(): Error: BtrieveClient::FileCreate():94:Permission error in ... samples\btest.php on line 38".

Using Btrieve with PHP on Ubuntu 20 x64

Documented below is one approach to configuring the Btrieve 2 SDK for the PHP programming language. In this example, we will use the PHP package to target an Ubuntu 20 x64 environment. It is assumed that Zen is already installed and running.

  • Install SWIG and PHP if not already installed.
    • Open a terminal window as a non-"root" user.
    • sudo apt install swig
    • sudo apt install php php-dev
  • Install the Btrieve 2 Linux SDK for Zen.
  • Generate, build, and install Btrieve PHP.
    • Open a terminal window as a non-"root" user.
    • Change directory into the Btrieve 2 SDK directory.
    • Generate Btrieve PHP.
      • swig -cppext cpp -outcurrentdir -php7 -c++ -Iinclude swig/btrievePhp.swig
        • Note that PHP version 7 is specified.
    • Build Btrieve PHP.
      • g++ -c -fPIC -Iinclude -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM btrievePhp_wrap.cpp
      • g++ -shared btrievePhp_wrap.o -o php_btrievePhp.so -L/usr/local/actianzen/lib64 -lbtrieveCpp
        • Note that the path to PHP used above may differ.
    • Install Btrieve PHP.
      • sudo cp btrievePhp.php /usr/local/actianzen/lib64
      • sudo cp php_btrievePhp.so /usr/local/actianzen/lib64
      • Configure PHP to load Btrieve PHP.
        • Update "/etc/php/7.4/cli/php.ini" as follows:
          • Add "/usr/local/actianzen/lib64" to "include_path".
          • Add "/usr/local/actianzen/lib64/php_btrievePhp.so" as an extension.
          • Note that the path to PHP used above may differ.
    • Execute the Btrieve PHP sample program.
      • export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/actianzen/lib64
      • php -f samples/btest.php x=9
        • You should see the output "{"x":9,"xSquared":81,"xSquareRoot":3}".
        • You may need to change the permissions of the current directory if you receive the error "PHP Warning: assert(): Error: BtrieveClient::FileCreate():94:Permission error in ... samples\btest.php on line 38".