Icon Sample Script

The following is a sample script that shows how to connect to a local configuration and database, open a table directly, and then display all of the rows in the table in an HTML table.

<?php

// First connect to the database

$con = edb_connect("type=local;charset=Ansi;configpath=C:\\Tutorial;"+
                   "uid=Administrator;pwd=EDBDefault;database=Tutorial");
if (!$con)
  {
  die("Could not connect: " . edb_errmsg());
  }

// Create a direct table open command

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

// Execute the command to get the table cursor

$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>";

?>
Image