...

View Full Version : BLOBing an Excel File



FuZion
08-09-2007, 05:52 PM
Hello,

I am trying to read a Microsoft Excel file into a database.. here is the code I am using:


$svcSheetHdl = fopen($_FILES['svcSheet']['tmp_name'], "r");
$svcSheetContent = fread($svcSheetHdl, $_FILES['svcSheet']['size']);
$svcSheetContent = addslashes ( $svcSheetContent );
fclose( $svcSheetHdl );

Then I simply put $svcSheetContent in an INSERT statement and run it. Unfortunately, I don't think addslashes is working correctly. Some of the quotes within the BLOB data are being read, even though they have been escaped, or should have been. I have tried using mysql_real_escape_string() and addslashes() and neither of them work. I have used this method before with no problem whatsoever, is this something with excel files?

What should I do, any ideas?

Any help is greatly appreciated.

Thanks,

FuZion

CFMaBiSmAd
08-09-2007, 06:19 PM
Some of the quotes within the BLOB data are being read, even though they have been escaped, or should have been.Are you getting an error when you INSERT or when you SELECT the data? Post any error messages... Give an example of what you see that shows the problem.

Also, what are the settings for - magic_quotes_runtime and magic_quotes_sybase?

Edit: I guess I recommend you show your code that is inserting the data into the database as well.

FuZion
08-09-2007, 08:21 PM
I am getting the error when I insert it, there are no error messages, the query just does not work. What I did was echoed the query to the page, then ran it in MySQL Query Browser. It gives me: "there is an error in your SQL syntax near: XXXXX" and then gives some of the blob code. I know it is not reading the entire thing as a string because of the way Query Browser color codes its syntax, only some of the BLOB is orange (a string), you can see where the quotes change it.

I'm not sure, would I find those values in my.ini?

CFMaBiSmAd
08-09-2007, 08:57 PM
Since you are receiving a syntax error in the query browser, your PHP script is also probably failing, but has no error checking or error reporting. Post your code to get any specific help with it. It is likely that your query is not formed correctly.

I just whipped up an upload/database insert script based on the code you posted above, and it works with a moderate size/complexity .xls file.

FuZion
08-10-2007, 02:31 AM
Here is the code:


$svcSheetHdl = fopen($_FILES['svcSheet']['tmp_name'], "r");
$svcSheetContent = fread($svcSheetHdl, $_FILES['svcSheet']['size']);
$svcSheetContent = addslashes ( $svcSheetContent );
fclose( $svcSheetHdl );


$query = "INSERT INTO `svcSheet` ( aid, date, number, xls_data ) VALUES ( " . $aid . ", STR_TO_DATE('" . $_POST['date'] . "', '%m/%d/%Y'), " . $_POST['number'] . ", '" . $svcSheetContent . "' )";


The query works fine without the xls data, but doesn't work with it, I have used this exact same method before with no problems so I'm not sure whats up.

Thanks a bunch for your help!

FuZion
08-10-2007, 04:53 AM
Could it be my PHP and/or MySQL settings?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum