Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

$Query .= "FROM employee ";
$Query .= "WHERE id=17 ";
$Result = odbc_do($Connection, $Query);


// make sure binmode is set for binary pass through
odbc_binmode($Result, ODBC_BINMODE_PASSTHRU);


// make sure longreadlen mode
// is set for echo to browser
odbc_longreadlen($Result, 0);


// get the first row, ignore the rest
odbc_fetch_row($Result);


// send header so browser knows it's a gif
header("Content-type: image/gif");


// get the picture
odbc_result($Result, 1);
?>


Table 13.8. ODBC Binary Data Modes
Mode Description

ODBC_BINMODE_PASSTHRU (^) Pass through as binary data
ODBC_BINMODE_RETURN (^) Return as hexadecimal codes
ODBC_BINMODE_CONVERT (^) Return with data converted to a string
odbc_close(integer connection)
Use odbc_close to close a connection to a database. If there are open transactions for the
connection, an error will be returned and the connection will not be closed.
<?
// connect to database
$Connection = odbc_connect("store", "guest", "guest");
// execute query
$Query = "SELECT price ";
$Query .= "FROM catalog ";
$Query .= "WHERE id=10 ";
$Result = odbc_do($Connection, $Query);
odbc_fetch_row($Result)
$price = odbc_result($Result, 1);
print("$price
\n");
odbc_close($Connection);
?>

Free download pdf