Insert image binary from xml data to mysql in PHP

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
satriaf
Forum Newbie
Posts: 1
Joined: Mon Feb 07, 2011 5:32 am

Insert image binary from xml data to mysql in PHP

Post by satriaf »

I have some photos (not big, only 8kb) in mysql database (in my desktop). the field type is blob. i want to export the table to xml file then upload it to my database website. but it not success. Here is what i have done : Exporting the data to xml (in my computer desktop):

Code: Select all

FileStream fs = new FileStream(filename,FileMode.Create,FileAccess.Write,FileShare.None);
StreamWriter sw = new StreamWriter(fs,Encoding.ASCII);
ds.WriteXml(sw);  //write the xml from the dataset ds
Then upload the xml from my joomla website. i load the xml before insert it to the database

Code: Select all

...
$obj = simplexml_load($filename);
$cnt = count($obj->mydata); //mydata is the table name in the xml tag
for($i=0;$i<cnt;$i++)
{
   ...
   $myphoto = 'NULL';
   if(!empty($obj->mydata[$i]->myphoto))
   {
      $myphoto = base64_code($obj->mydata[$i]->myphoto);
   }
   //insert to the database
   $sqlinsert = "insert into jos_myphoto (id,myphoto) values(".$i.",".$myphoto.")";
   ...
}
...
it keep telling me 'DB function failed'. when value of $myphoto is null, the query work well but if $myphoto is not null, the error appears. i think there is something wrong with the code

Code: Select all

$myphoto = base64_code($obj->mydata[$i]->myphoto)
. i try to remove base64_code function but it dont work. How to solve this problem? Sorry for my bad english
Post Reply