need help please.
Trying to write a text fie getting results from database. There are arround 100,000 records.
Its give me execution timeout error.
If I just display the records its work fine and dsiplay all the records in browser but when everr i try to store in Array and create a txt file using foreach I gets this error.
Any solutions please beside the time change in php.ini for execution. (I have no access to that file)
// this query will get all the data
// a db link for queries
$lh = mysql_connect( 'localhost', 'root', '' );
// and a controller link
$clh = mysql_connect( 'localhost', 'root', '', true );
if ( mysql_select_db ( 'databasename', $lh ) )
{
$began = time();
$tout = 60 * 5; // five minute limit
$qry = "SELECT tid, ticker, name from `datatable` order by tid ";
$rh = mysql_unbuffered_query( $qry, $lh );
$thread = mysql_thread_id ( $lh );
while(list($totid, $toticker, $toname) = mysql_fetch_row( $rh ) )
{
$snews11_c[]="$toticker,$toname\r\n";
//echo"$snews11_c<br>";
if ( ( time() - $began ) > $tout )
{
// this is taking too long
mysql_query( "KILL $thread", $clh );
break;
}
}
}
// get the result with for loop
if($snews11_c!=""){ foreach ( $snews11_c as $v11_c ) { if ( trim($v11_c)!="" or trim($v11_c)!="0" ) {
$mnews11_c = "$v11_c".$mnews11_c;
}
}
echo"$mnews11_c";
}
// assign some values for the top
$outputtextcri = "$mnews11_c";
//echo"outputtextcri";
// check if no data came
if($outputtextcri==""){
//header( "Location: ./anotherpage.php" );
} else {
$outputtext_c = "<ticker>,<name>\r\n$outputtextcri"; // day
//create file if not exist
$write_file_c = "./mydir/allrecords.txt";
$fp_c = @fopen($write_file_c, 'w+') or die("Couldn't open ".$write_file_c);
if (!$fp_c){ echo 'error in file : allrecords.txt<br>'; exit; }
@fwrite($fp_c, $outputtext_c);
@fclose($fp_c);
//header( "Location: ./main.php" );
//echo"created";
} // end of check if no data came from db
// closing connection
mysql_close($lh);
mysql_close($clh);