Php Apache2 Insert MSSQL Big Binary Error: changed database context to "database"

I have poured over the net and cannot find a solution to my problem.

I have a simple vector graphic upload form (ai, eps, pdf, svg) that converts them from imagemagik to jpgs and saves both files in MSSql 2000 in the "image" fields.

We get the error "MSSQL Error: Changed database context in" out-database "for anything uploaded more than 16 megabytes.

I know this is not the preferred way to store these files ... but it worked flawlessly for us until we started getting large files. It's also handy for how we handle versions and security.

I am processing apache and php log files and cant find one error being logged while doing this!

The webserver and mssql are powerful ram boat machines and are located on the same gigabit switch so I am not worried about performance. I just need it to work.

Again, this works flawlessly for anything less than 16 months old, which I can't find anywhere else.

**Our Web Server Specs**
2.6.38-11-server #50-Ubuntu
PHP Version 5.3.5-1ubuntu7.7
Apache Version  Apache/2.2.17 (Ubuntu)
Apache API Version  20051115
Max Requests    Per Child: 0 - Keep Alive: on - Max Per Connection: 100
Timeouts    Connection: 300 - Keep-Alive: 15

**Php mssql settings**
MSSQL Support   enabled
Active Persistent Links 0
Active Links    0
Library version FreeTDS
Directive   Local Value
mssql.allow_persistent  On
mssql.batchsize 0
mssql.charset   no value
mssql.compatability_mode    Off
mssql.connect_timeout   90
mssql.datetimeconvert   On
mssql.max_links Unlimited
mssql.max_persistent    Unlimited
mssql.max_procs Unlimited
mssql.min_error_severity    11
mssql.min_message_severity  11
mssql.secure_connection Off
mssql.textlimit 2147483647
mssql.textsize  2147483647
mssql.timeout   180

**Other relevant php.ini settings**
max_execution_time = 300
max_input_time = 300
memory_limit = 512M
post_max_size = 300M
upload_file_size = 300M
default_socket_timeout = 60
odbc.defaultlrl = 2147483647
odbc.defaultbinmode = 1

      

Relevant code snippet:

        $f1 = ("" .$outloc . $clean1 . "");
        $f1string  =  file_get_contents($f1); 
        $f1data  =  unpack("H*hex", $f1string);
        $cf1 = ("" .$outloc . $confilename1 . $outext . "");
        $cf1string  =  file_get_contents($cf1); 
        $cf1data  =  unpack("H*hex", $cf1string);
        $cf1name = ("" .$confilename1 . $outext. "");

        //Upload to database
        $query_result  =  mssql_query("INSERT INTO art_converted_table (image_blob,filename,comment,received_dt,image_name,contact_email,po_number,upload_blob,upload_mime,upload_filename) VALUES (0x".$cf1data['hex'].",'$cf1name','$ccomment','$received_dt','$clean1','$email','$cponum',0x".$f1data['hex'].",'$file1type','$clean1')", $db_conn)
        or die('MSSQL error: ' . mssql_get_last_message());

      

I tried to manually add sleep () timers after unpacking the process, which could be a problem. I'm just delusional as to why this is happening.

Is there a maximum length of a hexadecimal string that can be inserted into mssql?

Any help would be greatly appreciated!

Thank!

+3


source to share


1 answer


I faced a similar issue with large files and PHP and got around it using the PHP FTP extension as described here.

"http://au.php.net/manual/en/book.ftp.php"



Then I executed my query using mysql.exe and shell_exec (), you can also run the query from your web application.

If you decide to keep using the form then check the size of the post_max_size variable in php.ini, the form post might be a bottleneck.

0


source







All Articles