php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45812 Error in mssql_query when the script create large text files
Submitted: 2008-08-13 20:18 UTC Modified: 2008-08-21 01:00 UTC
From: leonardodeconti at yahoo dot com dot br Assigned: fmk (profile)
Status: No Feedback Package: MSSQL related
PHP Version: 5.2.6 OS: Linux 2.6.24.2
Private report: No CVE-ID: None
 [2008-08-13 20:18 UTC] leonardodeconti at yahoo dot com dot br
Description:
------------
Into of a loop(while):
1) I open the file handler (w)
2) Caught data on database (MSSQL 2005)
3) Record the data to file (fwrite)
4) Close handler
5) Continue loop until end

If the file created (step 3) is large (over +- 25MB), the next query gives error. But if the file is small, the script works well.

In my script, I have to make the export of large tables, separated.

If I remove the element 'large_table' of the array $tables, the export will work perfectly.



Reproduce code:
---------------
<?php
function replace_characters($value) {
   return str_replace("'","''",$value);
}

mssql_connect('server_name','user_name','passwrd') or die('error connect to database');
mssql_select_db('database_name');

$tables = array('large_table','medium_table','small_table','medium_table');
$hadler = '';
foreach($tables as $table) {
   $handler = fopen("$tabele.sql","w");
   $res_sql = mssql_query("SELECT * FROM $table");
   while($table_data = mssql_fetch_assoc($res_sql)) {
      $table_data = array_map('replace_characters',$table_data);
      fwrite($handler,"INSERT INTO $table values('".implode("','",$table_data)."');\n");
   }
   echo "\n$table exported";
   fclose($handler);
}
echo "export finished";
?>

Expected result:
----------------
large_table exported
medium_table exported
small_table exported
medium_table exported
end

Actual result:
--------------
large_table exported
Warning: mssql_query(): Query failed in /htdocs/export_data_as_sql_insert.php on line 15


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-14 00:01 UTC] nicos@php.net
Hello,

Could you tell me how many rows you have in that large base?

It seems dbsqlexec() fails because dbresults set wasn't processed entirely

According to the mssql's documentation:
The most common reason for failing is a SQL syntax error. dbsqlexec will also fail if there are semantic errors, such as incorrect column or table names. Failure occurs if any of the commands in the batch contains a semantic or syntax error. dbsqlexec also fails if previous results had not been processed, or if the command buffer was empty. 


 [2008-08-14 00:04 UTC] nicos@php.net
And please, provide a working reproductible script. Yours is full of typos.

Thank you.
 [2008-08-21 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC