ID:               45812
 Updated by:       [EMAIL PROTECTED]
 Reported By:      leonardodeconti at yahoo dot com dot br
-Status:           Verified
+Status:           Feedback
 Bug Type:         MSSQL related
 Operating System: Linux 2.6.24.2
 PHP Version:      5.2.6
 New Comment:

And please, provide a working reproductible script. Yours is full of
typos.

Thank you.


Previous Comments:
------------------------------------------------------------------------

[2008-08-14 00:01:52] [EMAIL PROTECTED]

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-13 20:18:42] 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



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45812&edit=1

Reply via email to