Reply to Re: update mysql blob with another blob using php

Your name:

Reply:


Posted by Jerry Stuckle on 10/13/10 11:26

sime wrote:
> Hi,
>
> I have a blob field in a mysql database table. I want to copy a blob
> from one record to another. I am having trouble transferring the data
> via a php variable. Maybe I need to addslashes or convert to Hex or
> something. I've tried a few things but can't quite get it. Here is
> simplified code.
>
> mysql_select_db($dbname, $connection);
>
> $query = "SELECT blobthing
> FROM mytable
> WHERE id = 1;";
>
> $results = mysql_query ($query, $connection);
> $row = (mysql_fetch_assoc($result));
> $varblobthing = $row['blobthing']; //put the blob in a variable
>
> $query = "UPDATE mytable
> SET blobthing = ".$varblobthing.",
> WHERE id = 2;";
>
> mysql_query ($query, $connection);
>
>
> I would love any advice I can get. Thanks in advance.
> Simon
>

Sime,

Three problems here. First of all, since $varblobthing is non-numeric,
you need to enclose it with "'" characters. Also, a blob can, by
definition, contain any character - including "special" ones like "'".
You need to use mysql_escape_string (or mysql_real_escape_string,
depending on your version of PHP and MySQL) to escape it.

Finally, get rid of the trailing ';' after the 2. You don't need a ';'
at the end of the SQL statement.

Try something like:

$query = "UPDATE mytable SET blobthing = '" .
mysql_escape_string($varblobthing) .
"' WHERE id=2";

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация