LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 07-21-2006, 03:45 AM   #1
prabhatsoni
Member
 
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:
Code:
$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
Quote:
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 03:48 AM.
 
Old 07-21-2006, 04:25 AM   #2
zeitounator
Member
 
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....

http://dev.mysql.com/doc/refman/5.0/...ng-syntax.html

Quote:
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, 06:01 AM   #3
prabhatsoni
Member
 
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
 
  


Reply

Tags
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 08:49 AM
Abiword --- Can't insert picture in table cell rickh Linux - Software 2 03-07-2006 01:53 PM
caps sensitivity in mysql table/field name Swakoo Linux - General 0 11-14-2005 02:16 AM
How to insert same text in one field for 10,000 records table edhan Linux - Newbie 6 06-13-2005 04:48 AM
Mysql - Howto insert 'admin' account into table ??? b:z Linux - General 6 03-29-2005 04:44 AM


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

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