English 中文(简体)
PHP/PDO/MySQL:在MEDIUMBLOB储存坏数据
原标题:PHP/PDO/MySQL: inserting into MEDIUMBLOB stores bad data

我有一个简单的PHP网络,通过文件上载接收icon图像,并在MEDIUMBLOB栏中储存。

在我的机器上(Windows)加上2台六氯环己烷服务器,这套机器可操作。 在第三台六氯环己烷服务器上,插入的图像被腐蚀:在选取后无法读取,而由MySQL公司(MySQL)功能报告的栏目数据长度大约比上载文档的尺寸高出40%。

(每个服务器连接MySQL的一个单独案例)

Of course, this leads me to think about encoding and character set issues. BLOB columns have no associated charsets, so it seems like the most likely culprit is PDO and its interpretation of the parameter value for that column.

  • I ve tried using bindValue with PDO::PARAM_LOB, to no effect.
  • I ve verified that the images are being received on the server correctly (i.e. am reading them post-upload with no problem), so it s definitely a DB/PDO issue.
  • I ve searched for obvious configuration differences between the servers, but I m not an expert in PHP configuration so I might have missed something.

插入法则大致如下:

$imagedata = file_get_contents($_FILES["icon"]["tmp_name"]);
$stmt = $pdo->prepare( insert into foo (theimage) values (:theimage) );
$stmt->bindValue( :theimage , $imagedata, PDO::PARAM_LOB);
$stmt->execute();

任何帮助都将得到真正的赞赏。

www.un.org/Depts/DGACM/index_spanish.htm 错失的服务器上的MySQL焦炭 is是8ut;它给他人留下了1.。

The problem is "solved" by adding PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES latin1 COLLATE latin1_general_ci" to the PDO constructor.

这似乎如a bug对我设计不好:为什么linkion<>>/em>的果园对双轨数据有任何影响,特别是当它被确认为与PARAM_LOB的双亲还是PDO?

Note that the DB tables are defined as latin1 in all cases: it s only the servers default charsets that are inconsistent.

最佳回答

这对我来说似乎是一种ug笑:为什么连接的果园对双轨一栏的数据有任何影响,特别是在与PARAM_LOB一起被确认为PDO的双亲时?

我并不认为这必须是ug。 我可以想象,每当客户与服务器进行会谈时,如果说以下指挥是在UTF-8,而服务器在拉丁-1中需要,那么问询就会重新编码,然后进行上层和执行。 因此,这是数据运输的一个编码问题。 由于这一重新编码将影响到以前的平级,因此,BLOB栏的二元数据也将发生变化。

From the Mysql manual:

www.un.org/Depts/DGACM/index_spanish.htm 服务器在接收后应翻译一份声明的特性是什么?

For this, the server uses the character_set_connection and collation_connection system variables. It converts statements sent by the client from character_set_client to character_set_connection (except for string literals that have an introducer such as _latin1 or _utf8). collation_connection is important for comparisons of literal strings. For comparisons of strings with column values, collation_connection does not matter because columns have their own collation, which has a higher collation precedence.

或者在回路上:来自仓库的拉丁1数据将转换成UTF-8,因为客户告诉服务器,它喜欢UTF-8进行运输。

“PDO”的识别特征是你的名字:

<>PDO:PARAM_LOB 指示项目事务厅将数据描绘成一个流子,以便你能够利用项目组合简化软件。 (Ref)

我没有我的SQL专家,但我要这样解释。 客户和服务器需要谈判它们正在使用哪些果园,我假定这样做是出于某种原因。

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...