Feedback
Did this article resolve your question/issue?

   

Article

Sample PHP Programs to Access a Progress DB through ODBC

Information

 
TitleSample PHP Programs to Access a Progress DB through ODBC
URL Name21017
Article Number000122100
EnvironmentProduct: Progress
Version: 9.x
Product: OpenEdge
Version: 10.x, 11.x to 11.6x inclusive
OS: All Supported Platforms
Other: ODBC Driver
Question/Problem Description
Sample PHP programs to access a Progress DB through SQL-92 ODBC Driver.
How to connect a PHP to a OpenEdge Database via ODBC
Steps to Reproduce
Clarifying Information
Error Message
Defect/Enhancement Number
Cause
Resolution
PHP (Hypertext Preprocessor) is a server-side, cross-platform, HTML embedded scripting language. It's freeware software that can be downloaded from the PHP Web site (http://www.php.net/).

In order to run these programs an ODBC Driver is required on the Web Server machine.
  • Create a System Data Source Name called sp2k.
  • The Sports2000 Database should be running
  • There should be a SQL-92 user defined as "sysprogress" with password "s".
The following two PHP 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.
  • The second example, records are printed "manually" one by one.
First PHP 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 PHP example, printing "manually" record by record:

If the constant, SQL_CUR_USE_ODBC, is not used in the odbc_connect function, the same records is repeated several times.
 
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);
}

Note:  If the ODBC connection is not working( e.g. receiving Internal Server Error 500) do the following:
 
Within the /etc/php.ini configuration file, search for “display_errors” and set the parameter to On.  
There may be two locations where this parameter is mentioned, ensure that only one is uncommented.
 
display_errors = On
 
Once set, rerun the PHP code and more information about the cause of the error should be displayed. 
Workaround
Notes
Progress Articles:

000031743, Using PHP with OpenEdge ODBC driver on Unix/Linux
000035694, How to configure the 64-bit OpenEdge ODBC driver to work with PHP on CentOS/RedHat/Oracle Linux versions 5 or 6, via Source builds.  
000027930, How to configure the 64-bit OpenEdge ODBC driver to work with PHP on CentOS/RedHat/Oracle Linux versions 5, 6 or 7 via Yum (embedded video)      

DISCLAIMER: This example code is provided for informational purposes only. Its inclusion in the Progress Support Knowledgebase does not constitute endorsement of it or support for it, nor does it guarantee that it has been tested to the extent recommended for application deployment. Programmers are advised that they use it at their own risk.
Last Modified Date6/17/2019 7:47 AM
Attachment 
Files
Disclaimer The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.