|  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
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: leonardodeconti at yahoo dot com dot br
New email:
PHP Version: OS:


 [2008-08-13 20:18 UTC] leonardodeconti at yahoo dot com dot br
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:
function replace_characters($value) {
   return str_replace("'","''",$value);

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

$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";
echo "export finished";

Expected result:
large_table exported
medium_table exported
small_table exported
medium_table exported

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-14 00:01 UTC]

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]
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: Mon May 27 14:01:32 2024 UTC