Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 07-21-2006, 02:45 AM   #1
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Rep: Reputation: 30
Can not insert word file into mysql table (in blob field)

Hello gurus,
I have a mysql table with one of field created as "mediumblob". This filed planned to use for saving files uploaded by users through apache+php.
Now I have this insert statement for inserting the file into the fields:
$data=fread(fopen($file_ln, "rb"), filesize($file_ln));   
$query="insert into mes values (\"" . $_SESSION['user_id'] . "\",\"" . $to[$i] . "\",\"" . $_POST['message'] . "\",now(),\"\",\"".$file_name."\",\"".$data."\")";
Where file_ln is the uploaded file.
Now this query works perfectly if a text file is uploaded, but fails when MS-word (or .xls etc) files are uploaded.
The error reported is
1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
What is the problem in this, folks. I feel there is som emismatch between the field type and the $data.
After uploading the .doc file, I have checked that the $data variable does save the file. This I have done by checking its size by "strlen($data)".

Any pointer friends.
Thanks in advance.

Prabhat Soni

Last edited by prabhatsoni; 07-21-2006 at 02:48 AM.
Old 07-21-2006, 03:25 AM   #2
Registered: Aug 2003
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262

Rep: Reputation: 30
I would bet this is a character escape problem....

Originally Posted by mysql doc
If you want to insert binary data into a string column (such as a BLOB column), the following characters must be represented by escape sequences:
NUL NUL byte (ASCII 0). Represent this character by \0 (a backslash followed by an ASCII 0 character).
\ Backslash (ASCII 92). Represent this character by \\.
' Single quote (ASCII 39). Represent this character by \'.
" Double quote (ASCII 34). Represent this character by \".
Have a look at the documentation for php mysql_real_escape_string() function
Old 07-21-2006, 05:01 AM   #3
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
Thanks Mr Zeitounator,

You have been of immense help.

Thanks onece again.

Prabhat Soni


binary, escape, mysql

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Recover a file saved in a mysql table via php upload prabhatsoni Linux - Software 0 07-13-2006 07:49 AM
Abiword --- Can't insert picture in table cell rickh Linux - Software 2 03-07-2006 12:53 PM
caps sensitivity in mysql table/field name Swakoo Linux - General 0 11-14-2005 01:16 AM
How to insert same text in one field for 10,000 records table edhan Linux - Newbie 6 06-13-2005 03:48 AM
Mysql - Howto insert 'admin' account into table ??? b:z Linux - General 6 03-29-2005 03:44 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:01 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration