Skip to main content

SQL for PHP PDO tutorial

SQL quick start tutorial for PHP programmers with the PDO extension

The SQL PHP PDO driver is designed specifically for interfacing with FairCom using PHP 7 and later with the PDO extension.

This tutorial helps PHP programmers use the FairCom SQL API for PHP to interact with FairCom servers.

Note

The <root> directory for this driver is <faircom>\drivers\php.sql.pdo\

  1. Install and start up the FairCom server if it is not currently running.

  2. Get started immediately with the source code found in the <faircom>\drivers\php.sql.pdo\tutorials directory, or proceed with the following instructions.

Originally, PHP was the acronym for Personal Home Page, but it now uses the recursive acronym PHP: Hypertext Preprocessor. PHP is a widely used scripting language that is especially suited for web development. The FairCom PHP drivers allow you to access the powerful FairCom SQL database from your PHP projects.

PHP is typically used to create database-driven web pages and websites. Originally, it used conventional SQL to access an underlying database to retrieve data, which determined many aspects of the pages it served up to the user. Developers have long recognized one drawback to this useful functionality: many databases use variations on "standard" SQL, which can make your application difficult to port to a different database.

To address this issue, the PHP development community has introduced the PHP Data Objects (PDO) extension for accessing a database. PDO gives you an abstraction layer so that your applications can use the same functions to issue queries regardless of the underlying database. The goal of PDO is to allow an application to be independent of the database it uses. This should allow a developer to change databases with no change in application coding or logic.

The FairCom package provides two types of PHP drivers, each in its own directory:

  • FairCom PHP PDO - supports PHP 7 using the PHP Data Object (PDO) extension.

    This is the preferred way to access the FairCom server from PHP.

  • FairCom PHP - supports PHP 5.

Note

FairCom formerly used PHP with ODBC but this method has been deprecated.

A connection string is required for every SQL interface. The connection string with all options, including TSL/SSL support, is shown below:

ctsql:port=6597;host=localhost;dbname=ctreeSQL;ssl=BASIC', 'admin', 'ADMIN'

The DSN portion is a single string delimited by semicolons. The rest of the options are comma-delimited.

  • port=

  • host=

  • dbname=

To execute the SQL PHP tutorials with Microsoft IIS on Windows, install PHP 7 with the PDO extension as follows:

Note

This section shows typical procedures using Windows 10.

  1. Open the Start Menu and click the Settings gear icon to bring up “Windows Settings”.

  2. In the search box, search for "Turn Windows features on or off" and select the application when it appears under the search box.

  3. In the "Windows Features" window, check the Internet Information Services checkbox and expand Internet Information Services, World Wide Web Services, and Application Development Features. 

  4. Check the box next to CGI.

    iis.svg
  5. Click OK and wait until the installation completes.

  6. Restart your computer.

  7. Verify that Windows IIS is functional by entering http://localhost into a browser address bar.

    A “Microsoft Internet Information Services” web page should appear.

To compile PHP, and compile and install the FairCom PHP PDO extension on Windows, follow these steps:

  1. Download the PHP 7 SDK. Just press the green “Code” button and select “Download ZIP”.

    A zip file with a name like “php-sdk-binary-tools-master.zip” will download.

  2. After the download has finished, extract all its files into the root of your C: drive.

  3. Rename the “C:\php-sdk-binary-tools-master” folder to “C:\php-sdk”.

    The “C:\php-sdk” folder should contain some “phpsdk-____.bat” files and other folders and files.

  4. Run the batch file of the version you want to use.

  5. Open a Developer Command Prompt window for the version of Microsoft Visual Studio you are using. 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 web page.

  6. In the Developer Command Prompt window, move to the C:\php-sdk folder.

  7. Execute the “phpsdk-______.bat” file that corresponds to the version of Visual Studio you chose. 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.bat

    vc14/vc15/vs16 is the version of Microsoft Visual Studio you chose to use.

    x64/x86 is 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 “$”:

  8. Execute one of the following commands:

    phpsdk_buildtree phpdev

    phpsdk_buildtree master

    The second command is used if you chose to use the “master” branch of PHP earlier.

    Depending on which batch file you run in this step, a “phpdev” or “master” folder tree will be created in your C:\php-dev folder, and you will be moved into a “working folder” in that folder tree. Make a note of the working folder, such as “C:\php-sdk\phpdev\vc15\x64,” shown in the image that appears. You will later be unzipping a TAR file into this folder.

  9. Download the version of PHP that you want to use. 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. Choose any one of them. The freely-available, open source 7zip program can be used to unzip any of them. If you chose the bz2 compression format, your file will have a name like php-7.4.8.tar.bz2.

  10. 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” (“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.

  11. In the Developer Command Prompt window, change directories to the new PHP folder you just created and filled from the tar file. You will probably need to change the version in php7-.4.8 to match the PHP version above.

  12. Download and extract the source code of all of the PHP dependencies by executing phpsdk_deps -u if you are not using the “master” branch. If you are using the “master” branch execute phpsdk_deps -u -b master

    The process may take a few minutes. It should finish with a message such as “Updates performed successfully.” It might display INFO: Could not find files for the given pattern(s) which is not a problem.

  13. At the Command Prompt, run the following based on the FairCom product you are using to specify your add-modules-dir. <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.

  14. Now run the following command 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 do some checks and print 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 Unknown option --with-pdo-ctsql, it means the “add-modules-dir” you specified was incorrect. Go back and verify that the folder exists.

    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.

  15. 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.

  16. At the 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. The “Release” folder should contain the “php.exe” application you just built. 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. You will need it in subsequent steps of these instructions and in the “Configure Microsoft IIS” instructions.

  17. Use a text editor to open the php.ini file you just created and search for lines ";extension_dir"

  18. 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""

  19. Find the section of the INI file that contains the commented-out list of extensions and find the line for “pdo_mysql”

  20. 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.

    If you are using PHP7.1.33, the extension line reads something like "extension=php_pdo_ctsql.dll"

  21. 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\

  22. 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 ..\Releasephp -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 previous steps.

  23. At this point, you can test the FairCom 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&gt;\Driver\sql.php.pdo\tutorials\PHP_Tutorial1.php

    c-treeEDGE

    FairCom-DB

    FairCom-EDGE

    FairCom-RTG

    php -f <basedir&gt;\drivers\php.sql.pdo\tutorials\PHP_Tutorial1.php

    It should print the HTML source code of a web page. If “ctsqlConnect: -20212 Error in Network Daemon” is shown, it means the FairCom server is not running. Start the FairCom server and re-do this step. The following is the correct output:

    <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 PHP tutorials

    See How to build PHP for more details. The instructions above do not follow that web page exactly.

To configure Windows IIS for PHP, follow these steps:

Note

This section shows typical procedures using Windows 7. Some of the dialog and labels may look different in other versions of Windows.

  1. Open the Start Menu, select Run, and execute InetMgr.exe.

  2. In the InetMgr main window, double-click Handler Mappings.

  3. In the Handler Mappings window, click Add Module Mapping... on the right-side Actions menu:

  4. Complete the "Add Module Mapping" dialog window with the following:

    Request Path: *.php

    Module: FastCgiModule

    Executable: This needs to be filled in with the full path to the “php-cgi.exe” executable that is in the “Release” folder created in Compile PHP and the PHP PDO extension (Windows). An example path would be “C:\php-sdk\phpdev\vc15\x64\Release\php-cgi.exe”.

    Name: PHP

    addmodulemapping.svg
  5. Click OK and then Yes on the "Add Script Map" message box that appears. Finally, close the InetMgr dialog.

  6. Restart your computer to ensure everything is configured.

FairCom PHP includes a set of tutorials intended for use with the PHP 7 PDO extension. To install and execute these tutorials with Microsoft Internet Information Service (IIS), be sure to install IIS and PHP 7.x.x as described in the previous sections. Next, you will need to copy the tutorial files into the IIS root directory as shown in this section.

  1. Copy the contents of the FairCom PHP PDO “tutorials” directory into the C:\inetpub\wwwroot directory. This requires Administrator privileges. The files are found in your FairCom installation folder:

    c-treeAce

    <faircom>\sdk\sql.php.pdo\tutorial

    c-treeRTG

    <faircom>\driver\sql.php.pdo\tutorials

    c-treeEDGE

    FairCom-DB

    FairCom-EDGE

    FairCom-RTG

    <faircom>\driver\php.sql.pdo\tutorials

  2. Open your favorite web browser and connect to http://localhost. You should see the index.htm page with hyperlinks to the three tutorials to be executed. Some systems you might have to use http://localhost/index.htm instead.

  3. Click on the tutorial hyperlinks to execute the tutorials.

If the following error is shown, it usually means the FairCom Database Engine is not running on your machine. The most likely cause is that the FairCom evaluation license times out after 3 hours and shuts down the server. The solution is to restart the server. See the Setup section for instructions.

Logon to server...

SQLSTATE[20212] ctsqlConnect: -20212 Error in Network Daemon - SQL ERROR [-20212

To install and execute FairCom PHP tutorials on Linux/Unix, consider using the package manager of the platform to avoid system settings errors.

PHP is included in many common Linux and Unix distributions. If needed, first download PHP 7 then complete the following procedures.

Requirements:

  • PHP 7 development package. This contains the files needed to build PHP extensions.

    To install on CentOS, use yum install php-devel

    To install on Ubuntu, use apt-get install php7-dev

  • Perl

  • Autoconf

  • Automake

  • GNU m4

  • C++ compiler

  1. Create the Configuration Script

    Move to the <faircom>/drivers/php.sql.pdo/src directory.

    Run the phpize command to create the configuration script:

    phpize

  2. Configure and Build

    Run the configure script to create the makefile containing the instructions to build the FairCom PHP extension:

    ./configure

    You should see the following line in the text that is printed:

    checking whether to enable PDO c-tree SQL support... yes, shared

    Build FairCom PHP PDO extension using make. If you change versions of PHP, you should do a make clean first, before doing make:

    make

    It should say “Build complete” when done. The extension will be created in the modules folder:<faircom>/drivers/php.sql.pdo/src/modules/pdo_ctsql.so

  3. Install the Extension

    Run the following command to Install the FairCom PHP extension into your PHP installation extensions directory:

    sudo make install

    Be sure the pdo.ctsql.so file has the same permissions as the other .so files in that install folder.

    Be sure php.ini is configured to load extensions from the PHP installation extensions directory. If you have a configure script with installed Autotools, follow these steps:

    > libtoolize 
    > aclocal 
    > autoreconf -i
    > phpize 
    > ./configure --with-pdo-ctsql

Before you configure PHP 7 you must compile and install the FairCom PHP PDO extension (pdo_ctsql.so) under your version of PHP.

To configure PHP 7 to run FairCom SQL PHP PDO follow these steps:

Note

These instructions are not valid for CentOS versions 6, 7, and 8. If followed, they will render PHP non-operational on those systems. If you are installing on one of those CentOS versions, see Instructions for CentOS.

  1. Open php.ini with your favorite text editor. In most installations, you will find the server (SAPI) version of php.ini in /etc/php/apache2/php.ini

    In Linux installations of PHP, there is often a separate php.ini file for SAPI (PHP served from a web server), and for CLI (PHP run from the Command Line). If you intend to test things from the command line, be sure to make the following changes to the CLI version of php.ini (usually /etc/php/cli/php.ini) as well as the SAPI version of php.ini.

  2. Search for extension_dir.

    If the extension_dir line is commented out (; on the beginning of the line) leave it that way, because the “make install” step during the build should have copied “pdo_ctsql.so” into the default extension folder

    If this line is not commented, it's better to copy pdo_ctsql.so into your default PHP extensions directory (the directory listed in the php.ini file).

  3. Search for extensions area and add extension=pdo_ctsql.so to configure the FairCom SQL PHP module into your PHP:

    ; If you wish to have an extension loaded automatically, use the following syntax
    ; 
    ;   extension=modulename.extension
    ;
    ; For example, on Windows:
    ;
    ;   extension=php_ldap.dll
    ;
    ; ... or under UNIX:
    ;
    ;   extension=php_ldap.so
    ;
    ; Note that it should be the name of the module only; no directory information
    ; needs to go here. Specify the location of the extension with the 
    ; extension_dir directive above.
    
    ; Example lines:
    
    ;extension=php_ldap.so
    ;extension=gd.so
    extension=pdo_ctsql.so

    Your copy of php.ini might have the extensions end with “.so” and it might not, depending on the version of PHP you are using. For this reason, we recommend that you follow the pattern of the other extensions already listed in the file. For example, find the existing “pdo_mysql” extension line, copy it, remove the leading semicolon, and then change two letters to make it say “pdo_ctsql”...

  4. Save the changes to php.ini and close your text editor. If desired, change the other php.ini file as well.

  5. The libctsqlapi.so file must be in either its original location when the PHP module was built or in a directory part of the library path.

    The pdo_ctsql module you just built should already know the location of libctsqlapi.so, because the build added the libctsqlapi.so directory to the pdo_ctsql.so module library path. So, unless you have renamed or deleted the folder, you should be OK. Later in deployment situations, you might need to put libctsqlapi.so in a more generic place, for example, you may have built pdo_ctsql.so on a different machine.

  6. Make sure the previous steps worked by launching PHP, as follows:

    php -v

    No error messages or warnings should be printed.

  7. If you previously modified the CLI version of php.ini, you can run the tutorials from the command line, as follows:

    php -f ../tutorials/PHP_Tutorial1.php

    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 PHP tutorials.

    It should print the HTML source code of a web page.

    If “error in tcp bind 111 - SQLSTATE[20212] ctsqlConnect: -20212 Error in Network Daemon - SQL ERROR [-20212]” is shown, it means the FairCom server is not running. Start the FairCom server and re-do this step.

    If “could not find driver - SQL ERROR [0]” is shown, it probably means that you did not edit the CLI version of php.ini above.

    Testing from the command line allows you to see the error messages, even if PHP fails to launch (because it is misconfigured). The tutorial files do not need to be copied to the web server's documents directory in order to do this test.

  8. From the root shell restart your web server with the following command:

    /etc/init.d/apache2 restart

The instructions for installing and configuring PHP on CentOS 6, 7, 8, are slightly different than the instructions for most flavors of Linux/Unix. Be sure to use these procedures if you are installing on one of these CentOS versions.

These instructions assume you are using a version of PHP 7 from remirepo. On CentOS 8, PHP 7 is provided by the default repositories. If you prefer to have the very latest version of PHP, though, the Remi repository makes that available.

Make sure your installed version of php-devel is exactly the same version as your PHP 7. To see what version of PHP you have installed, enter the following command:

php -v

If PHP 7 is not installed, you can install the version of PHP 7 you desire using the following:

yum-config-manager --enable remi-php__

sudo yum install php.....

Then execute the following to install the files that are needed for building PHP extensions:

sudo yum install php-devel-

Then execute the following to install the php-pdo extension:

sudo yum install php-pdo

For these procedures, the php.ini file should not be changed. Do not add FairCom entries to extension_dir and the extensions area of that file. Instead, perform the following steps for CentOS 6,7,8:

  1. Create file /etc/php.d/30-pdo_ctsql.ini with a single line:

    extension=pdo_ctsql.so

    Make sure this file has the same permissions as the other files in that directory.

  2. Some builds of CentOS do NOT include the static version of libc, which is needed for building the pdo_ctsql.so library. If the following build instructions give a link error "cannot find -lstdc+", you need to install the static version of libc, as follows:

    sudo yum install glibc-static libstdc+-static

  3. Make sure that a “__-pdo.ini” file also exists in that folder, with a file number that is lower than the file you created in step 1. Calling the file “20-pdo.ini” would be fine. It should contain a single line:

    extension=pdo

    Make sure this file has the same permissions as the other files in that directory.

  4. Build and install the FairCom PHP PDO extension (pdo_ctsql.so) under your version of PHP following the Compile the PHP PDO Extension instructions. Be sure it has the same permissions as the other .so files in that folder: /usr/lib64/php/modules/

  5. The libctsqlapi.so file must be in its original location when the PHP module was built or in a directory part of the library path.

    The pdo_ctsql module you just built should already know the location of libctsqlapi.so, because the build added the libctsqlapi.so directory to the pdo_ctsql.so module library path. So, unless you have renamed or deleted the folder, you should be OK. Later, in deployment situations, you might need to put libctsqlapi.so in a more generic place. For example, you may have built pdo_ctsql.so on a different machine.

  6. Make sure the previous steps worked by launching PHP, as follows:

    php -v

    No error messages or warnings should be printed.

    If PHP is unable to load dynamic library 'pdo_ctsql', it could mean that php-pdo is not installed.

  7. Run at least one of the tutorials from the command line, as follows:

    php -f ../tutorials/PHP_Tutorial1.php

    If an “ ctsqlConnect: -20212 Error in Network Daemon” error is shown, it means the FairCom server is not running. Start the FairCom 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 PHP tutorials.

    Testing from the command line allows you to see the error messages, even if PHP fails to launch (because it is misconfigured). The tutorial files do not need to be copied to the web server's documents directory in order to do this test.

  8. Restart your web server. For example, with Apache you would use the following command:

    sudo systemctl restart httpd

FairCom PHP includes a set of tutorials intended for use with the PHP 7 PDO extension. To execute these tutorials, copy the tutorials files into a directory accessible to your web server (here we use the web server root directory) as shown below:

  1. Open a root shell, move to /var/www/ and copy the contents of the<faircom>drivers/php.sql.pdo/tutorials/ directory:

    debian:~# cd /var/www/debian:/var/www# cp -v <faircom>/php.sql.pdo/tutorials/* .

    Adjust the path based on your installation directory.

  2. Make sure FairCom SQL is running.

  3. Open your favorite web browser and connect to http://localhost/index.htm (make sure you are using a proper URL if you did not use the web server root directory).

    You should see the index.htm page with hyperlinks to the three tutorials to be executed:

  4. Click the tutorials hyperlinks to execute the tutorials.

This quick start includes three programs that demonstrate how to create tables and indexes, insert, update, and delete records, and process multiple operations as a single atomic transaction.

This tutorial shows the basic use of the FairCom PHP Interface using the PDO (PHP Data Object) extension.

Note

The code shown in this section is found in the FairCom <faircom>\drivers\sql.php.pdo\tutorials folder.

  1. Initialize()

    Connects to the FairCom Database Engine.

  2. Define()

    Creates a customer master table named custmast.

  3. Manage()

    1. Deletes preexisting records.

    2. Adds records.

    3. Reads and displays the records.

  4. Done()

    Disconnects from FairCom Database Engine.

An error handling function is also included.

This tutorial builds some table/file relationships using the FairCom PHP Interface and the PDO (PHP Data Objects) extension to PHP.

This tutorial creates a simple order system with customer, order, order detail, and product tables. It inserts records in the tables and runs a query that lists each customer's name and the total amount of each order.

tut2.svg
  1. Initialize()

    Connects to the FairCom Database Engine.

  2. Define()

    Creates "custmast", "custordr", "ordritem" and the "itemmast" tables with related indexes.

  3. Manage()

    1. Adds records to each of these tables.

    2. Lists each customer's name and the total amount of each order.

  4. Done()

    Disconnects from FairCom Database Engine.

Transaction processing provides a safe method for guaranteeing the atomicity of multiple database operations spread across separate tables/files. Within a transaction, either all of the operations succeed or none of the operations succeed. This ensures that the integrity of the data in related tables/files remains.

  1. Initialize()

    Connects to the FairCom Database Engine.

  2. Define()

    Defines and creates our four tables/files.

  3. Manage()

    1. Logon onto a session.

    2. Create 4 tables each with an index.

    3. Add records in multiple tables under transaction processing control.

    4. Display the contents of the tables.

  4. Done()

    Disconnects from FairCom Database Engine which releases resources.

The most common cause of run-time error 133 is the FairCom Database Engine is not running on your machine. The most likely cause is that the evaluation license times out after 3 hours and shuts down the server. The solution is to start the server.

ERROR 133 occurs when the FairCom server is not running

TSError.svg

This section lists some of the errors that can occur when compiling and running these tutorials:

cl.exe not found! Please set the environment for Visual C/C++ compiler.

The most common cause of this error is running the BuildTutorials.bat file from a DOS shell or normal Windows command shell rather than from the Visual Studio Developer Command Prompt window.

Error MSB8036:

The Windows SDK version 10.0.15063.0 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution".

This build error happens because the Windows SDK version that this solution was built against (10.0.15063.0) does not match the Windows SDK version that is currently installed on your computer.

To fix this, right-click on the solution (not one of the individual projects), select Retarget Solution, and specify a Windows SDK installed on your computer.

TSStudio.svg

The versions of the Windows SDK installed on your computer will be automatically listed. Choose one and click OK to retarget the solution.

TSStudio2.svg