Icon edb_jsonrows

Generates the JSON for the rows of an Elevate Web Builder dataset from a cursor.

Syntax
edb_jsonrows(<CursorHandle>, <ResourceName>,
                     <DataSetName>, [<LocalizedDateTimeColumns>],
                     [<DataSetParams>], [<UserName>, <Password>])

<CursorHandle> =

Handle of cursor returned by edb_execute function

<ResourceName> =

String containing resource name to use for embedded BLOB URLs

<DataSetName> =

String containing dataset name to use for embedded BLOB URLs

<LocalizedDateTimeColumns> =

Boolean indicating whether to convert date/time columns to UTC time

<DataSetParams> =

String containing ampersand-delimited (&) list of dataset parameters to use for embedded BLOB URLs

<UserName> =

String containing user name to use for embedded BLOB URLs

<Password> =

String containing password to use for embedded BLOB URLs

Returns
The cursor rows as a JSON string
if successful, and FALSE if there are any errors

Usage
The edb_jsonrows function generates the rows for a cursor in Elevate Web Builder JSON format. The ResourceName parameter is used to indicate the base URL to use for any BLOB URLs in the JSON rows. Embedded URLs are used in Elevate Web Builder to load BLOB data on demand. The DataSetName parameter is used to indicate the dataset name to use for any BLOB URLs in the JSON rows. The dataset name is passed as a key-value parameter:

dataset=<DataSetName>

The complete URL used for embedded BLOB URLs would then be:

<ResourceName>load?dataset=<DataSetName>&col=<ColumnName>&row=<RowKey>

The LocalizeDateTimeColumns parameter indicates whether date/time columns should be converted from local time to UTC time after being retrieved from the cursor. The default value for this parameter is False.

The DataSetParams parameter is an ampersand-delimited (&) of URL parameters to pass through with the embedded BLOB URLs. This parameter is important if the dataset is a query that requires parameters for filtering.

The UserName and Password parameters are used for authentication with any embedded BLOB URLs. They are passed back to the web server as authentication parameters when the BLOB URLs are used by the Elevate Web Builder application to load the BLOB data. You must specify both parameters, otherwise the UserName parameter will be ignored.

Warning This function moves the current row pointer in the cursor.

Please see the Elevate Web Builder manual for more information on datasets and the JSON data formats used with them.

<?php

// The following script connects to an ElevateDB
// Server and database, prepares and executes a
// direct table open, and then handles the incoming
// Elevate Web Builder dataset requests for the
// column definitions, rows, or BLOB data
//
// THIS IS JUST FOR ILLUSTRATIVE PURPOSES
//
// If you really need to use the ElevateDB PHP
// Extension with Elevate Web Builder, please see
// the Elevate Web Builder PHP DataSet Manager
// included with Elevate Web Builder.  It requires
// much less coding, and handles the dataset JSON
// transparently

$con = edb_connect("type=remote;charset=Ansi;address=127.0.0.1;"+
                   "uid=Administrator;pwd=EDBDefault;database=Test");
if (!$con)
  {
  die("Could not connect: " . edb_errmsg());
  }

$cmd = edb_prepare($con,"customer",EDB_COMMAND_TABLE);

$cursor = edb_execute($cmd);

if (isset($_SERVER["HTTP_X_EWBUSER"]) and isset($_SERVER["HTTP_X_EWBPASSWORD"]))
   {
   $user = $_SERVER["HTTP_X_EWBUSER"];
   $pwd = $_SERVER["HTTP_X_EWBPASSWORD"];
   }
else if (isset($_GET["user"]) and isset($_GET["password"]))
   {
   $user = $_GET["user"];
   $pwd = $_GET["password"];
   }
else
   {
   $user = NULL;
   $pwd = NULL;
   }           

if ($_GET["method"])
   {
   switch ($_GET["method"])
      {
      case "columns":
         {
         $cols = edb_jsoncols($cursor);
         if ($cols)
            {
            header("Content-Type: application/json; charset=utf-8");
            echo $cols;
            }
         else
            {
            die "Error retrieving dataset columns (" . edb_errmsg() . ")";
            }
         break;
         }
      case "rows":
         {
         $rows = edb_jsonrows($cursor,$_SERVER["SCRIPT_NAME"],"customer",FALSE,$_GET,$user,$pwd);
         if ($rows)
            {
            header("Content-Type: application/json; charset=utf-8");
            echo $rows;
            }
         else
            {
            die "Error retrieving dataset rows (" . edb_errmsg() . ")";
            }
         break;
         }
      case "load":
         {
         $data = edb_jsonload($cursor,$_GET["column"],$_GET["row"]);
         $content_type = edb_jsonloadtype($cursor,$_GET["column"],$_GET["row"]);
         if ($content_type <> "")
            {
            header("Content-Type: " . $content_type);
            }
         echo $data;
         break;
         }
      }
  }
else
  {
  die "Dataset method not specified";
  }

edb_disconnect($con);
?>
Image