Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : ODBC Functions (Unified) : odbc_free_result

odbc_free_result

Free resources associated with a result (PHP 4, PHP 5)
bool odbc_free_result ( resource result_id )

Always returns TRUE.

odbc_free_result() only needs to be called if you are worried about using too much memory while your script is running. All result memory will automatically be freed when the script is finished. But, if you are sure you are not going to need the result data anymore in a script, you may call odbc_free_result(), and the memory associated with result_id will be freed.

Note:

If auto-commit is disabled (see odbc_autocommit()) and you call odbc_free_result() before committing, all pending transactions are rolled back.

Examples ( Source code ) » odbc_free_result

<?

$db_user        
"develUser";
$db_pass        "d3v3lpa55";
$db_name        "test";

if (
PHP_OS == 'WINNT') {
$db_host        "192.168.0.50";
$dsn =        "DRIVER={MySQL ODBC 3.51 Driver};" .
              
"CommLinks=tcpip(Host=$db_host);" .
              
"DatabaseName=$db_name;" .
              
"uid=$db_user; pwd=$db_pass";
}
else {
$db_host        "localhost";
$dsn =        "DRIVER={myodbc};" .
              
"CommLinks=tcpip(Host=$db_host);" .
              
"DatabaseName=$db_name;" .
              
"uid=$db_user; pwd=$db_pass";
}

$directdsn 'myodbc-test';


$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";
$rows odbc_num_rows($rh);
echo 
"num rows: $rows\n";
var_dump($rows);

$cols odbc_num_fields($rh);
echo 
"num fields: $cols\n";
var_dump($cols);

// fetch
while ($rr odbc_fetch_array($rh)) {
    
var_dump($rr);
}

// fetch a specific row
$rr odbc_fetch_array($rh3);
var_dump($rr);

// bad row
$rr odbc_fetch_array($rh200);
var_dump($rr);

// free the result
echo odbc_free_result($rh);
// for good measure
echo odbc_free_result($rh);


echo 
odbc_close($r);

?>

Code Examples / Notes » odbc_free_result

rogersd

odbc_free_result() is also the way to avoid the dreaded "Too many open cursor" error.

rich

("Note:  If auto-commit is disabled (see odbc_autocommit()) and you call odbc_free_result() before committing, all pending transactions are rolled back.")
I've looked thru the code, and that note is definitely wrong, at least in my environment (Windows/SQL Server).  odbc_free_result ultimately just calls SQLFreeStmt which has NO EFFECT on outstanding transactions.
In fact, it seems it must be wrong for all environments, because the SQLFreeStmt is bound to the destruction of the result resource.  So unset($result) would be just as dangerous - and you're randomly and unpredictably screwed if garbage collection reaps the result set before your transaction's done.


Change Language


Follow Navioo On Twitter
odbc_autocommit
odbc_binmode
odbc_close_all
odbc_close
odbc_columnprivileges
odbc_columns
odbc_commit
odbc_connect
odbc_cursor
odbc_data_source
odbc_do
odbc_error
odbc_errormsg
odbc_exec
odbc_execute
odbc_fetch_array
odbc_fetch_into
odbc_fetch_object
odbc_fetch_row
odbc_field_len
odbc_field_name
odbc_field_num
odbc_field_precision
odbc_field_scale
odbc_field_type
odbc_foreignkeys
odbc_free_result
odbc_gettypeinfo
odbc_longreadlen
odbc_next_result
odbc_num_fields
odbc_num_rows
odbc_pconnect
odbc_prepare
odbc_primarykeys
odbc_procedurecolumns
odbc_procedures
odbc_result_all
odbc_result
odbc_rollback
odbc_setoption
odbc_specialcolumns
odbc_statistics
odbc_tableprivileges
odbc_tables
eXTReMe Tracker