Icon edb_prepare

Prepares a command using an SQL statement, direct table access, or a stored procedure/function.

Syntax
edb_prepare(<ConnectionHandle>, <Command> [, <CommandType>])

<ConnectionHandle> =

Handle of connection returned by edb_connect function

<Command> =

SQL Statement |
Table Name |
Procedure/Function Name

<CommandType> =

EDB_COMMAND_TEXT (0) |
EDB_COMMAND_TABLE (1) |
EDB_COMMAND_PROCFUNC (2)

Returns
Command handle (INTEGER) if successful, or
FALSE if there are any errors

Usage
The edb_prepare function prepares a command, returning a newly-allocated command handle as a result. A command can be one of 3 types:

Command TypeDescription
EDB_COMMAND_TEXTThis command type (the default) allows you to specify any valid SQL statement or script as the command. If the command is an SQL statement and is a DML statement, it may also contained named parameters in the form of :<ParameterName>, where <ParameterName> is the name of the parameter to use. If the command is a script, then after executing this function, the named parameters for such a script will automatically be available.
EDB_COMMAND_TABLEThis command type allows you to specify a table name that you wish to open directly. Opening a table directly will allow you to perform index-based operations that you cannot necessarily perform with an SQL result set, such as changing the active index, finding a specific key, and setting a range on a set of starting and ending keys.
EDB_COMMAND_PROCFUNCThis command type allows you to specify a stored procedure/function name that you wish to execute. After executing this function for a stored procedure/function, the named parameters for such a procedure/function will automatically be available. Functions also have one extra system-generated parameter named "Result" that will contain the result of a function after it is executed.

Examples
<?php

// The following script connects to an ElevateDB
// Server and database, prepares a parameterized
// SELECT statement, sets the parameter values,
// executes the statement, and then displays the
// result set in an HTML table

$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,"SELECT * FROM customer WHERE State=:State");
edb_setparam($cmd,"State","FL");
$cursor = edb_execute($cmd);

echo "<table border=\"1\" cellpadding=\"3\">";

echo "<tr>";

// Dump out the column headers

for ($i = 0; $i < edb_colcount($cursor); $i++)
   {
   $colinfo = edb_colinfo($cursor,$i);
   echo "<td>" . $colinfo["Name"] . "</td>";
   }

echo "</tr>";

// Now dump out the rows

while (!edb_eof($cursor)):
   echo "<tr>";
   for ($i = 0; $i < edb_colcount($cursor); $i++)
      {
      $col = edb_getcol($cursor,$i);
      if (is_null($col))
         echo "<td>NULL</td>";
      else
         echo "<td>" . $col . "</td>";
      }
   echo "</tr>";
   edb_next($cursor);
endwhile;

echo "</table>";

edb_disconnect($con);
?>
Image