
December 22nd, 2006, 09:28 AM
|
|
Contributing User
|
|
Join Date: Apr 2007
Location: Hyderabad, AP, India
Posts: 49
Time spent in forums: 3 h 55 m 43 sec
Reputation Power: 2
|
|
|
SQL Server 2005 in PHP
Hi,
I have to use front end php and backend SQL Server 2005. I need to fetch data from a table in SQL Server 2005 database and create a Excel file. The table has more than 65000 records. I use the following code.
php Code:
Original
- php Code |
|
|
|
<? $sqlconnect=mssql_connect("host","user","password"); $sqldb=mssql_select_db("dbase_name",$sqlconnect); $sqlquery="select * from master_table;"; $results= mssql_query($sqlquery); $out = ""; while ($field = mssql_fetch_field($results)){ $out .= '"'.$field->name.'",'; } $out .="n"; while ($row = mssql_fetch_assoc($results)){ foreach ($row as $col=>$val){ $out .= '"'.$val.'",'; } $out .="n"; } mssql_close($sqlconnect); $f = fopen ('export.csv', 'w'); header('location:export.csv'); ?>
But, this code is too slow. It takes hours and no result. It works fine for a very small table. How else do I go about converting a very big table in SQl Server 2005 to Excel (.xls or .csv).
Any better code would be applaudable.
Thanx in advance.
Regards,
tvks
|