Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
ODBC to Delimited Text
Old 05-10-2010, 01:25 PM ODBC to Delimited Text
Skilled Talker

Posts: 80
Name: John
Location: Sacramento
Trades: 0
I swear there's a dirt simple function/solution; however, I am suffering from a mindflayer moment. Beyond looping through the results here's my sad monday morning attempt:

PHP Code:
   ob_start();
   
odbc_result_all($rs); // ## rs = Resultset
   
$out ob_get_contents();
   
ob_end_clean();

   
$lard = array("<table><tr><th>","<tr><td>","</th></tr>","</td></tr>","</table>");
   
$meat = array("</th><th>","</td><td>");

   
$out str_replace($lard""$out); // ## trim the fat
   
$out str_replace($meat","$out); // ## carve the meat 
Envision_frodo is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-10-2010, 02:18 PM Re: ODBC to Delimited Text
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Why not just use odbc_result and format the output however you want?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-10-2010, 05:20 PM Re: ODBC to Delimited Text
Skilled Talker

Posts: 80
Name: John
Location: Sacramento
Trades: 0
My (poor?) Reasoning:

1. Looping through using odbc_result seems to take longer in my testing (small scale - using the following method):
PHP Code:
 $out null;
 while (
$row odbc_fetch_row($rs))
  {
   foreach(
range(1,odbc_num_fields($rs)) as $i) {$out .= odbc_result($rs,$i).",";}
   
$out substr($out,0,-1)."\n";
  } 
2. I only recently stumbled across the function odbc_result_all and subsequently felt like a... fool for looping through the recordset in order to (essentially) do the same thing in countless scripts/apps to date.

3. Given the popularity of delimited based import/export and the existence of the aforementioned function (odbc_result_all) I naturally assumed that I just missed a similar function with similar purpose. Perhaps: odbc_result_csv? or the like.

Last edited by Envision_frodo; 05-10-2010 at 05:21 PM.. Reason: Fix Error
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Old 05-10-2010, 05:24 PM Re: ODBC to Delimited Text
Skilled Talker

Posts: 80
Name: John
Location: Sacramento
Trades: 0
So after a bit of thought (for a change), caffine, and your (Nullpointer) response, i'm thinking this might be a better solution:
PHP Code:
 $out null;
 while(
$row odbc_fetch_array($rs))
  {
   
$out .= implode(",",$row)."\n";
  } 
Thoughts?

Last edited by Envision_frodo; 05-10-2010 at 05:25 PM.. Reason: cosistency
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to ODBC to Delimited Text
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13502 seconds with 12 queries