note 60048 rejected from function.odbc-fetch-into by jacques

From: Date: Fri, 23 Dec 2005 23:28:49 +0000
Subject: note 60048 rejected from function.odbc-fetch-into by jacques
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100644@lists.php.net to get a copy of this message
Note Submitter: gregory at nutt dot ca ---- Personally, I like the mssql_fetch_object function for returning rows from MSSQL, but sometimes need to use ODBC and I really miss this ability. The function below named odbc_fetch_object should return a similar result. The following is based on code I use but I haven't tested this example. <?php function run_odbc_query() { // Connect to the database $link = odbc_pconnect ("DSN", "login", "password", SQL_CUR_USE_ODBC); // If the $link isn't valid, quit if (!$link) { $dberror = "Couldn't connect to Database server!"; print $dberror; odbc_close($link); return; } // Define query $querystring = "select something from table"; // Run the query $result = odbc_exec($link, $querystring); // if there is a result, let's process it if(isset($result) && $result) { $objectresult=odbc_fetch_object($result); } $count = 0; while($count < count($objectresult)) { print $objectresult[$count]->something; $count++; } } function odbc_fetch_object($query) { // Get the field names and put them in an array for($i=1; $i <= odbc_num_fields($result); $i++) $varname[] = odbc_field_name($result, $i); // Loop to get the query result rows $count1 = 0; while (odbc_fetch_into($result, $result_array)) { $count2 = 0; while($count2 < count($result_array)) { // Assign the row values to the array variables $row_meta[$count1]->{$varname[$count2]} = $result_array[$count2]; $count2++; } $count1++; } return $row_meta; } ?>

« previous php.notes (#100644) next »