You are here: Re: update mysql blob with another blob using php « PHP Programming Language « IT news, forums, messages
Re: update mysql blob with another blob using php

Posted by Andy Hassall on 11/14/09 11:26

On 10 Sep 2005 10:36:06 -0700, "sime" <get_simon_hobbs@hotmail.com> wrote:

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

You've said you are "having trouble", yet you have not described what
"trouble" you're having, you've only posted some code.

> mysql_query ($query, $connection);
>
>I would love any advice I can get.

MySQL and PHP can give you advice for starters; make sure error_reporting is
set to E_ALL, and check the result code of every mysql_* call; if it returns
false, use mysql_error() to print a full error message.

> $query = "UPDATE mytable
> SET blobthing = ".$varblobthing.",
> WHERE id = 2;";

You're missing quotes around the value, escaping using mysql_escape_string,
and what's that comma at the end of the second line for?


Or, an alternative approach:
(http://dev.mysql.com/doc/mysql/en/example-user-variables.html)

mysql> create table t (id int, b blob);
Query OK, 0 rows affected (0.09 sec)

mysql> insert into t values (1, 'one');
Query OK, 1 row affected (0.06 sec)

mysql> select * from t;
+------+------+
| id | b |
+------+------+
| 1 | one |
| 2 | two |
+------+------+
2 rows in set (0.00 sec)

mysql> insert into t values (2, 'two');
Query OK, 1 row affected (0.00 sec)

mysql> select @b:=b from t where id=1;
+-------+
| @b:=b |
+-------+
| one |
+-------+
1 row in set (0.08 sec)

mysql> update t set b=@b where id=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from t;
+------+------+
| id | b |
+------+------+
| 1 | one |
| 2 | one |
+------+------+
2 rows in set (0.00 sec)

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

Navigation:

[Reply to this 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

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