1

I'm having a big problem

when i try to put the query string in the file the following error appears

Incorrect string value: '\ XE6 \ x00 \ x00 \ xfd \ xfd \ xfd ...'

INSERT INTO `web_plugins` (`nome`, `xmllocal_nome`, `icone_url`, `icone_bytecode`, `swf_url`, `swf_bytecode`) VALUES ('asdfasdf', 'wqwerrwe', '/assets/uploads/plugins_icons/f2d2d3d9.gif', 'GIF89a\0\0�\0\0������������������������������������������������������������������������������������������������������������������������������~~~}}}|||{{{zzzyyywwwvvvuuutttsssrrrqqqpppooonnnmmmjjjfffdddbbb```___]]]\\\\\\ZZZYYYXXXWWWRRRQQQCCC@@@888���\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0!�\0\0Q\0,\0\0\0\0\0\0\0��\'KP?BI2/?\02G&-*8\'+;\rNL:!.\"%)\"\'&\'-=B!1)$(%&$�1H;+\',-(&%%#�!4\Z\'))�Ժ(##!94)*$#�\'*&# \"#-/\'\"��$! <>!$!!\"HP���2>���_��p���c��,�H����6F�:�Qr+4�0aF�b�L�8�� \n���b&�]�Øï¿½I�
4
  • What type is the column swf_bytecode? What character set are you using? (I suggest UTF-8.) Commented Apr 23, 2013 at 18:21
  • @showdev the encoding should be irrelevant, swf_bytecode should be really a BLOB. Commented Apr 23, 2013 at 18:22
  • is not swf_bytecode, is icone_bytecode, I am already using UTF-8 Commented Apr 23, 2013 at 18:23
  • the type field in db is mediumtext Commented Apr 23, 2013 at 18:23

1 Answer 1

1

You should save the gif in a BLOB column.

Imagine the following table:

CREATE TABLE testblob(
  id INT AUTO_INCREMENT ,
  data MEDIUMBLOB,
  PRIMARY KEY ( id )
) ENGINE = InnoDB;

Then you can use the following INSERT code:

<?php
    $dbh = mysql_connect("localhost", "user");
    mysql_select_db("test");
    $data = file_get_contents("your.gif");
    // This is important to avoid a ' to accidentally close a string
    $data = mysql_real_escape_string($data);
    mysql_query("INSERT INTO testblob(data) VALUES ('$data')");
?>

Note that this is taken from an article from the web. Thanks to the author.

Further you should note, that the mysql_* extension has been marked deprecated. You should use the PDO or mysqli extension instead. I personally prefer PDO. Here comes an example that uses PDO:

$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);

// create a prepared statement
$stmt = $conn->prepare('INSERT INTO `testblob` (`data`) VALUES (:data)');    
// assign the blob value to it
$stmt->bindParam(1, file_get_contents('your.gif'), PDO::PARAM_LOB);

// execute the statemt
$stmt->execute();
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.