Problem with inserting BLOB into mysql DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cboileau
Forum Newbie
Posts: 8
Joined: Sun Nov 02, 2008 8:28 am

Problem with inserting BLOB into mysql DB

Post by cboileau »

Here is the snipet of code from the script. The echo on line 3 goes through, so i know the imgdata variable is defined, however it will not insert it into the database.

Code: Select all

$imgurl="http://www.wowarmory.com/wow-icons/_images/43x43/inv_helmet_134.png";
$imgdata=open_page($imgurl,1,2,0,0,0,$postcontent);
echo $imgdata;
mysql_query("Insert into `items` (`icon`) VALUES('$imgdata')");
$findid=mysql_insert_id();
$Select_img=mysql_query("Select * from items where id='$findid'");
$img=mysql_fetch_array($Select_img);
echo "$img[icon]";
If I change it around to be the following, it does the insert however, but obviously only with the word test.

Code: Select all

$imgurl="http://www.wowarmory.com/wow-icons/_images/43x43/inv_helmet_134.png";
$imgdata="test";
mysql_query("Insert into `items` (`icon`) VALUES('$imgdata')");
$findid=mysql_insert_id();
$Select_img=mysql_query("Select * from items where id='$findid'");
$img=mysql_fetch_array($Select_img);
echo "$img[icon]";
Any ideas? Thanks guys
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: Problem with inserting BLOB into mysql DB

Post by Burrito »

what does open_page() do?
cboileau
Forum Newbie
Posts: 8
Joined: Sun Nov 02, 2008 8:28 am

Re: Problem with inserting BLOB into mysql DB

Post by cboileau »

Its a customer function similar to curl, basicly pulls the image data from the file on the website. That function is working fine in this case though, because i can echo its output perfectly, it just wont insert it.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: Problem with inserting BLOB into mysql DB

Post by Burrito »

when you say you see its output perfectly, do you mean you see the binary string or you see the image?

I would replace your open_page() function with file_get_contents() to get the binary string of the file and dump that into your database.
Post Reply