Icon edb_jsoncols

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

Syntax
edb_jsoncols(<CursorHandle>)

<CursorHandle> =

Handle of cursor returned by edb_execute function

Returns
The column definitions as a JSON string
if successful, and FALSE if there are any errors

Usage
The edb_jsoncols function generates the column definitions for a cursor in Elevate Web Builder JSON format.

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