0

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):

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

...
$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 $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

1 Answer 1

1

Your data may contain which needs escaping put mysql_real_escape_string() function and try

It is always a good habit to store data using this function which save you from sql injection also.

And put quotes around the column data.

$sqlinsert = "insert into jos_myphoto (id,myphoto) 
values(".$i.",'".mysql_real_eascape_string($myphoto)."')";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.