Introduction

pjjTextBase is a set of powerful yet easy to use 20+ functions that provides a complete management for a simple relational database system, with data kept in industry standard text files (CSV, flat files).

This section shows some sample sample code.

Source : ➠ www.pjj.pl/pjjtextbase/


Note

  1. As of PHP 7.1 a $string will not convert to an $array.
    Therefore an error will occur in function ptb_select().
    The variable $result = ''; should be changed to $result = array(); in file pjjtextbase.php at line 425.
  2. When a select returns an empty $result and a $sort is included, you get an error in function ptb_sort().
    To prevent that, change line 442 from :
    if (is_array($result)) {
    to :
    if (count($result)) {
  3. As of PHP 7 eregi is obsolete. The alternative is to use preg_match.
    Instead of using the sample code from the manual :
    $x = ptb_select($myDatabase, "eregi('text_to_look_for', 'author')");
    use this :
    $x = ptb_select($myDatabase, "preg_match('/text_to_look_for/i', 'author')");
    It will also work in PHP 5.

This is the code to display the array below (for display purposes, some lines wrap. The ↵ character indicates it. The character is not part of the code) :

$path_to_db_script = $_SERVER['DOCUMENT_ROOT']↵
           . "/" . "db/pjjtextbase.php";
require $path_to_db_script;
$novels = ptb_connect('novels.csv');
$hercule = ptb_select(
        $novels,
        "'@protagonist' == 1 AND 'year' == 1953",
        'title ASC'
print_r ($hercule);

This is the output :

Array
(
    [0] => Array
        (
            [id] => 43
            [year] => 1953
            [@protagonist] => 1
            [title] => After the Funeral
            [%aka] => 18
            [protagonist] => Poirot, Hercule
            [@nationality] => 1
            [nationality] => Belgian
            [aka] => Array
                (
                    [0] => Funerals Are Fatal
                )

        )

)

And here is a record :

$theItem = 0;
echo $hercule[$theItem]["id"] . " - " . ↵
     $hercule[$theItem]["protagonist"] . " - " . ↵
          $hercule[$theItem]["title"];

43 - Poirot, Hercule - After the Funeral

Feb 17 2021 06:30:53