Kbase 21017: Two Sample PHP Programs to Access a Progress DB through ODBC
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  30/08/2010 |
|
Status: Verified
GOAL:
Two sample PHP programs to access a Progress DB through SQL-92 ODBC Driver.
GOAL:
How to connect a PHP to a OpenEdge Database via ODBC
FACT(s) (Environment):
Progress 9.x
OpenEdge 10.x
All Supported Operating Systems
FIX:
In order to run these programs an ODBC driver on your Web Server machine is required. Create a System Data Source Name called sp2k. The Sports2000 Database should be running and there should be a SQL-92 user defined as "sysprogress" with password "s".
These two examples produce the same HTML page. The first example uses the PHP function odbc_result_all() which prints all the records with a specific format. In the second example the records are printed "manually", one by one.
-- First example, using odbc_result_all():
<? php $sql="SELECT * FROM PUB.Customer";
if ($conn_id=odbc_connect("sp2k","sysprogress","s", SQL_CUR_USE_ODBC)){
echo "connected to DSN: $dsn";
if($result=odbc_do($conn_id, $sql)) {
echo "executing '$sql'";
echo " Results: ";
odbc_result_all($result, "BGCOLOR='#AAFFAA' border=3 width=30% bordercolordark='#FF0000'");
echo "freeing result";
odbc_free_result($result);
}else{
echo "can not execute '$sql' ";
}
echo " closing connection $conn_id";
odbc_close($conn_id);
}else{
echo " can not connect to DSN: $dsn ";
}
?>
-- Second example, printing "manually" record by record:
if ($conn_id=odbc_connect("sp2k","sysprogress","s", SQL_CUR_USE_ODBC )){
echo " connected to DSN: sports91b ";
if($cur=odbc_exec($conn_id, "SELECT * FROM PUB.Customer")) {
$Fields = odbc_num_fields($cur);
print "<=table border='1' width='100%'> <=tr>'";
// Build Column Headers
for ($i=1; $i <= $Fields; $i++){
printf("<=th bgcolor='silver'>%s <=/th>", odbc_field_name( $cur,$i)); }
// Table Body
$Outer=0;
while( odbc_fetch_row( $cur )){
$Outer++;
print "<=tr>";
for($i=1; $i <= $Fields; $i++){
printf("<=td>%s<=/td>", odbc_result( $cur, $i ));
}
print "<=/tr>";
}
print "<=/table>";
print " Your request returned $Outer rows!";
}
odbc_close( $conn_id);
}