[Typo3] Experience with odbc_connect, odbc_exec, etc.

Nick Weisser typo3 at openstream.ch
Tue Aug 16 12:22:10 CEST 2005


Hi there,

I did some futher testing and was actually able to connect to Access and 
extract the contents of the database via a simple PHP script inserted as 
PHP Content Element (Ext: page_php_content).

But when I use the very same code from within my own extension, I do not 
get any output (and error messages).

My debugging showed that the connection can be established, but when the 
script reaches the while loop to fetch the result rows, it somehow gets 
stuck.

In my apache2 error.log I have some strange entries:

-----------------------------------------------------------------------
*** glibc detected *** free(): invalid next size (fast): 0x08d22550 ***
Error at Line : parse error near limit
[Tue Aug 16 12:12:41 2005] [notice] child pid 30603 exit signal Aborted (6)
*** glibc detected *** corrupted double-linked list: 0x08e5a718 ***
[Tue Aug 16 12:16:58 2005] [notice] child pid 30682 exit signal Aborted (6)
-----------------------------------------------------------------------

Here is the extension code:

-----------------------------------------------------------------------
function main($content,$conf)	{
		$this->conf=$conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		$this->pi_USER_INT_obj=1;	
		$GLOBALS['TSFE']->set_no_cache();
//		ini_set('error_reporting', E_ALL);
	
		$cfg_dsn = "Catalog";
		$cfg_dsn_login = "";
		$cfg_dsn_mdp = "";
			
		$nrows=0;
		
		if ($conn)
		{
		$sql =  "select * from R_Material";
		//this function will execute the sql satament
		$result=odbc_exec($conn, $sql);

		$content .= "<table  align=\"center\" border=\"1\" borderColor=\"\" 
cellpadding=\"0\" cellspacing=\"0\">\n";
		$content .= "<tr> ";
		// -- print field name
		$colName = odbc_num_fields($result);

		for ($j=1; $j<= $colName; $j++)
		{
		$content .= "<th  align=\"left\" bgcolor=\"#CCCCCC\" > <font 
color=\"#990000\"> ";
		$content .= odbc_field_name ($result, $j );
		$content .= "</font> </th>";
		}
		$j=$j-1;
		$c=0;

		// The script works fine up to this point
                 // I can insert a die() function up to this point as
                 // well!
                 // If inserted inside the following while loop, though, 

                 // the die() function is ignored even though the page is
                 // called with "?&no_cache=1"
		
		// end of field names
		while(odbc_fetch_row($result)) // getting data
		{
		 $c=$c+1;
		 if ( $c%2 == 0 )
		 $content .= "<tr bgcolor=\"#d0d0d0\" >\n";
		 else
		 $content .= "<tr bgcolor=\"#eeeeee\">\n";
		   for($i=1;$i<=odbc_num_fields($result);$i++)
			 {
			   $content .= "<td>";
			   $content .= odbc_result($result,$i);
			   $content .= "</td>";
			   if ( $i%$j == 0 )
				   {
				   $nrows+=1; // counting no of rows
				 }
			 }
		   $content .= "</tr>";
		}
		
		$content .= "</td> </tr>\n";
		$content .= "</table >\n";
		// --end of table
		if ($nrows==0) $content .= "<br/><center> Nothing for $month yet! Try 
back later</center>  <br/>";
		else $content .= "<br/><center> Total Records:  $nrows </center>  <br/>";
		odbc_close ($conn);

		
		}
		else $content .= "odbc not connected <br>";
			
		return $this->pi_wrapInBaseClass($content);
	}
}
-----------------------------------------------------------------------

Any suggestions or pointers would be thankfully appreciated :-)
-- 
Kind regards
Nick Weisser

Openstream Internet Solutions
http://openstream.ch



More information about the TYPO3-english mailing list