Newbie questions about odbc...
| From: | Ryan_Robertson at 3com dot com | Date: | Fri, 17 Dec 1999 18:20:26 +0000 |
| Subject: | Newbie questions about odbc... | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-8078@lists.php.net to get a copy of this message | ||
Hey Everyone,
I'm having some problems getting an ODBC connection to work correctly. I get a
valid connection to the DB and can query and print out results, but the page
never completes. I receive the following message in the NT event viewer "The
HTTP server encountered an unhandled exception while processing the ISAPI
Application "<pathname>\php4isapi.dll".
Everything works just fine if I DON'T call odbc_exec or odbc_do. If I just open
the db and close it, the page completes just fine.
Below is the code I'm using, any ideas would be greatly appreciated.
Thanks!
Ryan Robertson
Palm Development Support
---------------------------------------
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?
//__________________________________________________________//
// test_odbc.php3// A sample PHP script to test ODBC under PHP / WinNT
//__________________________________________________________
function Error_Handler( $msg, $cnx )\
{
echo "$msg \n";
// in case of persistent connexion, it is important to close it before
exiting.
odbc_close( $cnx ); exit();
}
// create an ODBC connection, returned in $cnx
$cnx = odbc_connect( 'odbcdsname' , 'name', 'pass' );
if( ! $cnx ) {
Error_handler( "Error in odbc_connect" , $cnx );
}
// send a simple odbc query . returns an odbc cursor
$cur= odbc_exec( $cnx, "select * from KB_Article_Type ORDER BY Type_Name"
);
if( ! $cur ) {
Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
}
echo "<table
border=1><tr><th>Name</th><th>ID</th></tr>\n";
$nbrow=0;
// fetch the succesive result rows
while( odbc_fetch_row( $cur ) )
{
$nbrow++;
// get the field "id"
$id= odbc_result( $cur, 1 );
// get the field "nom"
$nom= odbc_result( $cur, 2 );
echo "<tr><td>$id</td><td>$nom</td></tr>\n";
}
echo "<tr><td colspan=2>$nbrow entries
</td></tr></table>";
// close the connection. important if persistent connection are "On"
odbc_close( $cnx );
?>
</body>
</html>