5

オブジェクトをデータベースに保存して取得した後、ウェブサイトの多くのようにオフセットエラーが発生します。保存しないと、すべて正常に動作します。

$serializedObject = serialize($this);
$unSerializedObject = unserialize($serializedObject);

また、データを保存してデータベースから取得するときに base64 エンコーディングを使用していますが、これは役に立ちません。でも逃げることはしない。私のオブジェクトは文字列を処理します。私が見つけたのは、この文字列で次のことです。

A woman is travelling around the world. She is 28 years old and she is from Great Britain.
She cannot use a car or a plane on her

それは正常に動作します。しかし、もう 1 つスペースと [旅] という単語を追加すると、エラーが表示されます。この 1 つの単語を含む文字列は次のとおりです。

A woman is travelling around the world. She is 28 years old and she is from Great Britain.
She cannot use a car or a plane on her journey

私の質問は、なぜエラーがポップアップするのですか?

これserialize($this)は、単語のないテキストに対する実行の出力ですjourney

これserialize($this)は、単語を含むテキストに対する実行の出力ですjourney

アップデート

オブジェクトを保存しているテーブルには文字セットがutf-8あり、BLOB タイプであるため文字セットが定義されていない列があります。mb_detect_encoding(serialize($this))リターン_UTF-8

のエスケープはありません$sql。これは、私が使用している Kohana フレームワーク内でクエリが実行される方法です。

$result = mysql_query($sql, $this->_connection)
4

2 に答える 2

3

この問題は、次のアプローチで修正されます。

$toDatabse = base64_encode(serialize($data));  // Save to database
$fromDatabase = unserialize(base64_decode($data)); //Getting Save Format 

しかし、疑問が残ります。Baba関数findSerializeErrorによって検出されたエラーの根本的な原因は何ですか?

于 2013-10-19T18:10:18.847 に答える