php.sql.pdo\tutorials\PHP_Tutorial1.php
This tutorial will take you through the basic use of the FairCom DB PHP Interface using the PDO (PHP Data Object) extension.
As with all other examples in the c-tree tutorial series, this tutorial simplifies the creation and use of a database into four simple steps: Initialize(), Define(), Manage(), and You’re Done() !
Note: The code shown in this section is found in the version of the tutorial that uses the FairCom DB sql.php API. If you are using the FairCom DB ODBC API to interface with PHP, the general flow of the tutorial will be the same, but the specifics will differ in some places due to the differences between sql.php and ODBC. Consult the source code for the specific version of the tutorial you are using for the exact coding techniques.
Tutorial #1: Introductory - Simple Single Table
We wanted to keep this program as simple as possible. This program does the following:
Note our simple PHP script:
<?php
print("<html>\n");
print("<head>\n");
print("\t<title>PHP Tutorial 1</title>\n");
print("</head>\n");
print("<body>\n");
//
// Implementation of the concept of "init, define, manage and you're done..."
//
$session = Initialize();
Defines($session);
Manage($session);
Done($session);
//
// The four steps are defined in the next sections of this tutorial.
//
print("</body>\n");
print("</html>\n");
// end of PHP_Tutorial1.php
?>
An error handling function is also included in the tutorial:
function Handle_Error($hdl, $msg) {
$SUCCESS = 00000;
$TABLE_ALREADY_EXISTS = 20041;
$INDEX_ALREADY_EXISTS = 20028;
$err = $hdl->errorCode();
if ($err == $SUCCESS || $err == $TABLE_ALREADY_EXISTS || $err == $INDEX_ALREADY_EXISTS)
return;
print("$msg - SQL ERROR: [$err] - " . $hdl->errorInfo()[2] . " <br>\n");
print("*** Execution aborted *** <br>\n");
exit();
}
We suggest opening the source code with your own editor.
Continue now to review these four steps.