Exemplo n.º 1
0
<?php

include 'connect.inc';
$r = odbc_connect($directdsn, $db_user, $db_pass);
//var_dump($r);
echo "resource? " . is_resource($r) . "\n";
if (!$r) {
    echo odbc_errormsg();
    exit(1);
}
$rh = odbc_exec($r, "SELECT * FROM my_table");
if (!$rh) {
    echo "odbc_exec failed!\n";
    echo odbc_errormsg();
    echo odbc_close($r);
    exit(1);
}
//var_dump($rh);
echo "resource? " . is_resource($rh) . "\n";
// odbc_cursor
echo odbc_cursor($rh) . "\n";
// fields
echo odbc_field_len($rh, 1) . "\n";
echo odbc_field_precision($rh, 2) . "\n";
echo odbc_field_scale($rh, 3) . "\n";
echo odbc_field_name($rh, 2) . "\n";
echo odbc_field_num($rh, 'field2') . "\n";
echo odbc_field_type($rh, 3) . "\n";
echo odbc_close($r);
Exemplo n.º 2
0
<?php 
if (isset($dbuser)) {
    echo "Connecting to {$dsn} as {$dbuser}\n";
    $conn = odbc_connect($dsn, $dbuser, $dbpwd);
    if (!$conn) {
        ?>
<H2>Error connecting to database! Check DSN, username and password</H2>
<?php 
    } else {
        ?>
 - OK<p>
Updating table "php_test"
<?php 
        odbc_autocommit($conn, 0);
        if ($result = odbc_do($conn, 'select * from php_test where b>1002 for update')) {
            $cursor = odbc_cursor($result);
            if ($upd = odbc_prepare($conn, "update php_test set a=?, b=? where current of {$cursor}")) {
                while (odbc_fetch_row($result)) {
                    $params[0] = odbc_result($result, 1) . "(*)";
                    $params[1] = odbc_result($result, 2) + 2000;
                    odbc_execute($upd, $params);
                }
                odbc_commit($conn);
            }
        }
        if ($result && $upd) {
            ?>
 - OK<p>
<H3>The table "php_test" should now contain the following values:</H3>
<table>
 <tr>